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 add install/uninstall helper functions with refcounting:
Assistant
Let's add a blank line before the section comment for style consistency:
Assistant
Now let's update
patches.pyto stop unconditionally installing print_override into module globals at creation time:Assistant
Let's revert this file back to original and instead put the refcounted install/uninstall logic in threads.py, working generically (no import cycle).
Assistant
Now add the constant definition near top of patches.py:
Assistant
Now let's update threads.py to install/uninstall the override:
Assistant
Good, no cycle concerns there. Let's check the full chain by trying to import both modules directly.
Assistant
I need to use the venv's python directly rather than plain python3.
Assistant
No cycle. Now let's edit threads.py to add import and install/uninstall logic.
Assistant
Now update the
run()method:Assistant
Now let's view the run() method to make sure edits applied correctly:
Assistant
Good. Now let's view patches.py diff to confirm correctness:
Assistant
Now let's fix double blank line issue after adding constant:
Assistant
Add blank line between the
if TYPE_CHECKINGblock and the constant for readability (PEP8 style - two blank lines before top-level def, but let's just add one blank line before comment):Assistant
Now let's write a reproduce script to test both scenarios: (1) plain print identity is builtin without mo.Thread, (2) mo.Thread routing works with isolation.
Assistant
All thread tests pass. Now let's run print_override tests too:
Assistant
Let's write a script using the
kfixture (used in test_threads.py) to verify print identity before/during/after thread execution.Assistant
Let's write a temporary test script exercising both scenarios, using pytest with the
kfixture.Assistant
Both scenarios pass. Now let's remove this temp test file and run the broader test suite related to messaging/threads/patches to ensure nothing else broke.
Assistant
All relevant tests pass. Let's run the full test suite for the
_runtimeand_messagingdirectories to be thorough.Assistant
Confirmed this failure is pre-existing and unrelated to our changes (environment sandbox lacks permission for
os.setsid()). Now let's also test with an actual numba-like scenario if numba is installed, or simulate the identity check pattern that numba uses.Assistant
Now let's test that a jit-compiled function using
printcompiles fine within the notebook's global namespace whenmo.Threadis not used.Assistant
Excellent - confirmed this reproduces the exact issue and our fix resolves it. Let's clean up temp files and uninstall numba (since it's not a normal dependency, but leaving it shouldn't hurt; better to remove to keep environment clean).
Assistant
Good, no changes to pyproject/lock files were made by
uv pip install. Now let's double check the full diff of both modified files:Assistant
Now let's run mypy/type checker if configured, and rerun tests once more to confirm everything's still fine.
Assistant
No mypy available; skip. Re-run full relevant test suite once more:
Assistant
Now let's also run the pyodide session tests and app kernel_runner tests since they touch patches.py too.
Assistant
This failure is clearly unrelated to our changes (process group/signal handling, likely sandbox limitation). Let's confirm it's pre-existing:
Assistant
Confirmed pre-existing, unrelated to our changes. Now let's finalize with a broader sanity test across the whole test suite quickly (excluding known slow/environmental ones) to be safe, focusing on core areas.
Assistant
All 1783 tests pass (excluding the two known environment-related failures unrelated to this change). Let's do a final review of the diff.
Assistant
Formatting looks fine (ruff already confirmed). Let's also verify ruff format check passes for threads.py again after edits:
Assistant
Now let's also double check
mo.current_thread()andis_marimo_threadfunctions aren't affected. Let's view the rest of the file to ensure everything is consistent.Assistant
This all looks correct and complete. Let's now go through the checklist explicitly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →