Skip to content

Commit

Permalink
fix: mpl.interactive should not hang when running as a script (marimo…
Browse files Browse the repository at this point in the history
…-team#1870)

* fix: mpl.interactive running as a script

* remove log warning
  • Loading branch information
akshayka authored Jul 24, 2024
1 parent 79c3a55 commit f92506e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions marimo/_plugins/stateless/mpl/_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
from starlette.websockets import WebSocketState

from marimo._output.builder import h
from marimo._output.formatting import as_html
from marimo._output.hypertext import Html
from marimo._output.rich_help import mddoc
from marimo._runtime.cell_lifecycle_item import CellLifecycleItem
from marimo._runtime.context import (
ContextNotInitializedError,
RuntimeContext,
get_context,
)
from marimo._runtime.context.kernel_context import KernelRuntimeContext
from marimo._server.utils import find_free_port
from marimo._utils.signals import get_signals

Expand Down Expand Up @@ -259,12 +260,9 @@ def interactive(figure: "Figure | Axes") -> Html: # type: ignore[name-defined]
if isinstance(figure, Axes):
figure = figure.get_figure()

try:
ctx = get_context()
except ContextNotInitializedError as err:
raise RuntimeError(
"marimo.mpl.interactive can't be used when running as a script."
) from err
ctx = get_context()
if not isinstance(ctx, KernelRuntimeContext):
return as_html(figure)

# Figure Manager, Any type because matplotlib doesn't have typings
figure_manager = new_figure_manager_given_figure(id(figure), figure)
Expand Down

0 comments on commit f92506e

Please sign in to comment.