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
I'll investigate how Marimo routes
printand how that interacts with Numba compilation. - Assistant
Implementing lazy
printoverride installation: only patch whenmo.Threadis used so Numba keeps the builtinprint. - Assistant
Adding tests for lazy installation and builtin print identity:
- Assistant
Fixing a circular import by lazy-importing
install_print_overrideinThread.__init__. - Assistant
Verifying Numba compilation with the fix:
- Assistant
printis no longer patched at kernel startup. It stays the builtin unlessmo.Threadis used, which keeps Numba happy while preserving thread output routing.Problem
Marimo always replaced
printin the kernel's__main__namespace withprint_overrideat startup. Numba requires the real builtinprintat compile time, so notebooks using Numba failed even when they never usedmo.Thread.Fix
- Lazy installation — Added
install_print_override()inprint_override.py, called fromThread.__init__when a marimo runtime context exists. - No startup patch —
runtime.pyand the test session helper now passprint_override_fn=Nonetopatch_main_module.
Behavior
Scenario printidentityThread output routing Notebook without mo.Thread - Lazy installation — Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.