Repository navigation
Show exceptions from threads in the python cell that started them - #1536
Merged
Merged
Conversation
A cell whose threads all raised still read "completed": threads did not inherit the cell's context, and threading runs its excepthook outside the thread's context, so the tracebacks arrived as unattributed background output. Launch the worker with -X thread_inherit_context=1, and wrap threading.excepthook to print each traceback as output of the cell that started the thread and to count it while that cell runs. The done frame gains defaulted thread_exceptions and first_thread_exception fields, and the python tool's status line reports them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AnthonyRonning
enabled auto-merge (squash)
November 10, 2026 05:45
AnthonyRonning
disabled auto-merge
November 10, 2026 05:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A cell that starts threads now reports their exceptions instead of looking like a clean success.
Why
In real use, a cell ran eight subinterpreters through
call_in_thread. Every thread raised, yet the cell returnedcompletedand printed a bogus speedup. The tracebacks appeared only as "Background stderr (unattributed native/subprocess output)".The cause: in CPython 3.14, threads do not inherit a cell's context by default, so the worker could not tell which cell their output belonged to.
What changed
-X thread_inherit_context=1, so threads a cell starts carry its execution id, and their output lands in that cell's stdout and stderr.threading.excepthookruns after the thread leaves its context, so the worker wraps it and reads the cell's id from the thread. The original hook still prints the traceback, now attributed to the cell. Uncaught thread exceptions are counted while that cell runs, and the first one's type and message are kept.SystemExitis ignored, as the default hook ignores it.completed (132 ms); 8 exceptions in threads started by this cell (first: NotShareableError: func not shareable); tracebacks in stderrA cell without thread exceptions renders exactly as before, and a completed cell is still not an error.
Caveats
asyncio.to_threadcopies the caller's context, so it is unaffected. Exceptions from pool work go to futures, never to these counts.Thread._context, guarded withgetattr. The host requires exactly CPython 3.14.7 at startup.Validation
SystemExitis not counted, and that a late thread exception is neither counted in the next cell nor left unlabelled. It fails without the change, without the hook, and without the flag.just ci-lintandjust ci-testpass, with 2,844 workspace tests and 26 worker tests.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.