A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: mpl.interactive should not hang when running as a script (#1870)
Akshay Agrawalf92506efdeeb
diff --git a/marimo/_plugins/stateless/mpl/_mpl.py b/marimo/_plugins/stateless/mpl/_mpl.pyindex b4bb0b2676..af07ff07cb 100644--- a/marimo/_plugins/stateless/mpl/_mpl.py+++ b/marimo/_plugins/stateless/mpl/_mpl.py@@ -20,14 +20,15 @@ from typing import TYPE_CHECKING, Any, Optional, Tuplefrom starlette.websockets import WebSocketStatefrom marimo._output.builder import h+from marimo._output.formatting import as_htmlfrom marimo._output.hypertext import Htmlfrom marimo._output.rich_help import mddocfrom marimo._runtime.cell_lifecycle_item import CellLifecycleItemfrom marimo._runtime.context import (- ContextNotInitializedError,RuntimeContext,get_context,)+from marimo._runtime.context.kernel_context import KernelRuntimeContextfrom marimo._server.utils import find_free_portfrom marimo._utils.signals import get_signals@@ -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 typingsfigure_manager = new_figure_manager_given_figure(id(figure), figure)