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 why that breaks Numba compilation whenmo.Threadisn't used. - Assistant
Numba fails when
printis patched in__main__globals because it can't type the custom function. I'll defer installing the override untilmo.Threadis first used. - Assistant
Implementing lazy print override installation and updating the related files.
- Assistant
Adding tests for lazy print override installation:
- Assistant
Fixing a circular import by deferring the
install_print_overrideimport insideThread.__init__. - Assistant
Fixed by deferring print override installation until
mo.Threadis first used.Problem
Marimo always patched
printin the kernel's__main__globals at startup. Numba resolvesprintfrom module globals at compile time and fails when it finds a custom function instead of the builtin:codeTypingError: Untyped global name 'print': Cannot determine Numba type of <class 'function'>Solution
install_print_override()inprint_override.py— idempotently patches__main__when needed.mo.Thread.__init__— callsinstall_print_override()lazily (with a deferred import to avoid circular imports).- Kernel startup — no longer passes
print_overrideintopatch_main_module, soprintstays as the builtin via__builtins__until a thread is created.
Behavior
Scenario printin globals
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.