Marimo's print routing breaks Numba compilation In notebooks that do not use mo.Thread,…
- User
Marimo's print routing breaks Numba compilation
In notebooks that do not use
mo.Thread,printmust retain builtin identity so Numba can compile functions that call it.mo.Threadmust continue routing output to the spawning cell, with output isolation between concurrent threads.Interface
No new interfaces are introduced.
- Assistant
Now remove the eager injection plumbing.
patches.py: - Assistant
Now
kernel_lifecycle.py: - Assistant
Now
runtime.py: - Assistant
Now update
print_override.py's docstring to reflect the lazy installation, and the test helper: - Assistant
Now add the regression tests to
tests/_runtime/test_threads.py: - Assistant
All 17 pass. Let me check for tests that assert on the module globals or patches directly:
- Assistant
That failure is unrelated — it needs built frontend assets (
marimo/_static/index.htmldoesn't exist in this checkout). Let me confirm it fails without my changes: - Assistant
Pre-existing failure, unrelated. Now run the broader runtime suite:
- Assistant
All 1182 runtime tests pass. Now the messaging tests and type/lint check:
- Assistant
Those 4 are pre-existing (unrelated docstring rules). Now the format check that got short-circuited:
- Assistant
Now an end-to-end sanity check — is Numba available to test the real scenario?
- Assistant
The Numba part passed — the error is a typo in my ad-hoc script. Rerun cleanly:
- Assistant
Both scenarios verified end-to-end with real Numba. Final diff review:
- Assistant
One last check — any docs referencing the old behavior:
- Assistant
The fix is complete and verified. Summary of what was done:
Problem
The kernel eagerly injected
print_overrideinto every notebook's globals at startup (patches.py), soprintin user code never resolved to the builtin. Numba can only compile calls to the builtinprint, so any@njitfunction callingprintfailed to compile — even in notebooks that never touch .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.