Skip to content

Commit

Permalink
fix: jedi stack overflow bug (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayka authored Apr 4, 2024
1 parent 6da85df commit 32c3264
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
8 changes: 0 additions & 8 deletions frontend/src/core/pyodide/worker/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class DefaultWasmController implements WasmController {
}

await this.installMarimoAndDeps(pyodide, version);
this.installPatches(pyodide);

return pyodide;
}
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion marimo/_pyodide/pyodide_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions marimo/_runtime/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit 32c3264

Please sign in to comment.