Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix leaked message #1861

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading