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 view the full
__init__around the KernelRuntimeContext branch to add the patch call at the right spot.Assistant
Now let's insert the call to this helper inside the
KernelRuntimeContextbranch:Assistant
Now update
runtime.pyto stop always installing print_override at kernel creation:Assistant
Now remove the now-unused import of
print_overridein runtime.py:Assistant
Now let's view the final threads.py file to double check correctness:
Assistant
The fix works as intended. Now let's run the existing test suite related to threads and print_override to ensure nothing is broken.
Assistant
Let's check that test file to see if it covers print routing scenario, and also run broader runtime tests.
Assistant
Good,
test_thread_printexercises exactly the scenario. It already passed. Now let's add a quick check for the "no thread" builtin-identity case as an ad-hoc script (not committed to tests) using thekfixture pattern via pytest to be thorough. Let's check thekfixture/conftest to understand default kernel setup fortest_threads.py.Assistant
Confirmed pre-existing failure unrelated to our change (environment sandbox restriction on
os.setsid()). Let's continue running the rest of the test suite excluding that test.Assistant
All passing. Now run messaging tests and a broader sweep to be safe.
Assistant
Now let's also run the pyodide-related tests to ensure nothing broke there, and a broader session test.
Assistant
Confirmed pre-existing failures unrelated to this change (sandbox/environment process constraints). Now let's double check final diff.
Assistant
No changelog file present. Now let's run ruff/lint checks on the modified files to ensure code style compliance.
Assistant
Let's do a final full check running the whole test suite quickly (excluding known-flaky/broken by sandbox tests) to be extra safe, focusing especially on runtime, messaging, and any print-related tests.
Assistant
All passing. Now let's review the checklist explicitly.
Assistant
Checklist review:
- If an error was reported in the issue description, I have successfully reproduced it. The issue described a design flaw (not a crash traceback):
printwas always monkey-patched at kernel startup viaprint_override_fn=print_override, meaningprintin the notebook's__main__module was never the actual builtin, even in notebooks that never touchmo.Thread. I reproduced this precisely with a script that spins up a real kernel session (viakernel_lifecycle.create_kernel) and confirmedsys.modules["__main__"].__dict__.get("print", builtins.print) is builtins.printwasFalsebefore my fix (i.e.,printwas always the wrapper, not the builtin) — this is the exact condition Numba would choke on.
- If an error was reported in the issue description, I have successfully reproduced it. The issue described a design flaw (not a crash traceback):
Assistant
Confirmed the bug reproduces on the original code (before my fix):
printis always the override, never the true builtin — this is exactly what would break Numba compilation, even for notebooks that never usemo.Thread.Assistant
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Confirmed above: with
print_override_fn=None(the new production default inlaunch_kernel),printin the notebook module remains the actual builtin when nomo.Threadis created. I also confirmed via the earlier/tmp/repro_print.pyscript that once amo.Threadis constructed,printgets lazily patched toprint_override, andtest_thread_print(existing test) confirms output still correctly routes to the spawning cell with isolation from the main thread's stream. -
I have thought about edge cases and made sure my fix handles them as well.
-
Assistant
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran
tests/_runtimeandtests/_messagingfully (1444 passed), plustests/_pyodideandtests/_session(2 pre-existing failures unrelated to this change, confirmed identical on the unmodified codebase viagit stash). Also specifically re-rantest_threads.pyandtest_print_override.py, all passing.
Final diff review before submitting:
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.