Skip to content

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.

fix: jedi stack overflow bug (#1066)

Akshay Agrawal32c32642e793
diff --git a/frontend/src/core/pyodide/worker/bootstrap.ts b/frontend/src/core/pyodide/worker/bootstrap.ts
index 663179eb3e..2f5db48575 100644
--- a/frontend/src/core/pyodide/worker/bootstrap.ts
+++ b/frontend/src/core/pyodide/worker/bootstrap.ts
@@ -24,7 +24,6 @@ export class DefaultWasmController implements WasmController {
}
await this.installMarimoAndDeps(pyodide, version);
- this.installPatches(pyodide);
return pyodide;
}
@@ -79,13 +78,6 @@ export class DefaultWasmController implements WasmController {
`);
}
- private installPatches(pyodide: PyodideInterface) {
- pyodide.runPython(`
- import pyodide_http
- pyodide_http.patch_urllib()
- `);
- }
-
async startSession(opts: {
queryParameters: Record<string, string | string[]>;
code: string | null;
diff --git a/marimo/_pyodide/pyodide_session.py b/marimo/_pyodide/pyodide_session.py
index 6fd1058ab4..68b886bab3 100644
--- a/marimo/_pyodide/pyodide_session.py
+++ b/marimo/_pyodide/pyodide_session.py
@@ -18,7 +18,7 @@ from marimo._pyodide.streams import (
PyodideStdout,
PyodideStream,
)
-from marimo._runtime import handlers, requests
+from marimo._runtime import handlers, patches, requests
from marimo._runtime.context import initialize_context
from marimo._runtime.input_override import input_override
from marimo._runtime.marimo_pdb import MarimoPdb
@@ -324,6 +324,13 @@ def launch_pyodide_kernel(
LOGGER.debug("Launching kernel")
+ # Patches for pyodide compatibility
+ patches.patch_pyodide_networking()
+
+ # Some libraries mess with Python's default recursion limit, which becomes
+ # a problem when running with Pyodide.
+ patches.patch_recursion_limit(limit=1000)
+
# Create communication channels
stream = PyodideStream(on_message, input_queue)
stdout = PyodideStdout(stream)
diff --git a/marimo/_runtime/patches.py b/marimo/_runtime/patches.py
index cd6f12fc3c..71af514a45 100644
--- a/marimo/_runtime/patches.py
+++ b/marimo/_runtime/patches.py
@@ -23,6 +23,21 @@ def patch_sys_module(module: types.ModuleType) -> None:
sys.modules[module.__name__] = module
+def patch_pyodide_networking() -> None:
+ import pyodide_http # type: ignore
+
+ pyodide_http.patch_urllib()
+
+
+def patch_recursion_limit(limit: int) -> None:
+ """Set the recursion limit."""
+
+ # jedi increases the recursion limit as a side effect, upon import ...
+ import jedi # type: ignore # noqa: F401
+
+ sys.setrecursionlimit(limit)
+
+
def patch_micropip(glbls: dict[Any, Any]) -> None:
"""Mock micropip with no-ops"""