ISSUE DESCRIPTION Marimo's print routing breaks Numba compilation In notebooks that do…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /marimo, current file: none) bash-$
Assistant
Now let's look at patches.py where print_override is set into module dict.
Assistant
Confirmed the bug reproduction. Now let's verify with true builtin print it works.
Assistant
Good, no further references. Now let's update threads.py to lazily install the print override, guarding against circular imports.
Assistant
These tests test print_override directly and should still pass unmodified. Let's run them.
Assistant
All pass. Now let's write a reproduction test that mimics the kernel and thread flow end-to-end.
Assistant
All 3 tests pass now (including the numba compile test). Let's clean up temp test files and restore the venv's numpy/numba to original state.
Assistant
Restored. Now let's run the full relevant test suites to make sure nothing else broke.
Assistant
All pass. Now let's run the broader
_runtimetest directory and_messagingto check nothing else is broken.Assistant
Confirmed pre-existing environment issue unrelated to our fix. Now let's run the wider test suite quickly for the
_ai,_output, etc. related to threads/print just to be safe, plus check ruff/lint.Assistant
Good —
get_context()is already thread-local, so concurrentmo.Threads each have their own context/cell_id, preserving output isolation. This is unchanged and already covered by the existing tests (test_thread_print,test_thread_output_append,test_thread_has_own_stream). Let's also test concurrent threads output isolation explicitly with a quick script.Assistant
Isolation confirmed. Clean up temp test file.
Assistant
Now let's run the full existing test suite one more time broadly (excluding e2e/frontend) to be confident, focusing on relevant dirs, and check no numpy version drift issue remains.
Assistant
Only the known pre-existing environment failure remains (unrelated
os.setsid()permission issue confirmed above). Everything else passes, numpy version is restored. Let's view the final diff once more for review.Assistant
This looks clean and minimal. Now let's go through the checklist.
Assistant
Checklist review:
- I have successfully reproduced the reported error: Yes — I wrote a standalone repro script (
repro_numba.py) that mimicked marimo'sprint_overrideinstallation into a module's globals and confirmed Numba'snjitcompilation fails withTypingError: Untyped global name 'print'whenprintis shadowed in module globals (even though the override forwards to the real builtin at runtime). I also confirmed via a real marimoKerneltest that installingnumbaand JIT-compiling a function usingprint()fails without the fix.
- I have successfully reproduced the reported error: Yes — I wrote a standalone repro script (
Assistant
- I have confirmed that my fix resolves the error: Yes — after the fix, I re-ran the temporary reproduction test suite (
test_print_is_builtin_without_thread,test_numba_compiles_without_thread,test_print_overridden_after_thread) against a real marimoKernel, and all passed:printkeeps builtin identity (is builtins.print) whenmo.Threadis not used, Numba successfully JIT-compiles a function callingprint, and oncemo.Threadis created,printbecomes the routing override (is not builtins.print) as expected. I removed the temporary test files afterward, per instructions.
- I have confirmed that my fix resolves the error: Yes — after the fix, I re-ran the temporary reproduction test suite (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.