Skip to content

Commit

Permalink
fix leaked message (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur-ob authored May 27, 2024
1 parent a0b4f09 commit 34ecc5a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions metaflow/runner/nbrun.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import ast
import os
import shutil
import tempfile
from typing import Dict, Optional

from metaflow import Runner

try:
from IPython import get_ipython

ipython = get_ipython()
except ModuleNotFoundError:
print("'nbrun' requires an interactive python environment (such as Jupyter)")

DEFAULT_DIR = tempfile.gettempdir()


def get_current_cell():
def get_current_cell(ipython):
if ipython:
return ipython.history_manager.input_hist_raw[-1]
return None
Expand Down Expand Up @@ -56,7 +48,17 @@ def __init__(
base_dir: str = DEFAULT_DIR,
**kwargs,
):
self.cell = get_current_cell()
try:
from IPython import get_ipython

ipython = get_ipython()
except ModuleNotFoundError:
print(
"'nbrun' requires an interactive python environment (such as Jupyter)"
)
return

self.cell = get_current_cell(ipython)
self.flow = flow
self.show_output = show_output

Expand Down

0 comments on commit 34ecc5a

Please sign in to comment.