Enable setting and resetting a thread-local parent header - #1546
Open
jasongrout wants to merge 6 commits into
Open
Enable setting and resetting a thread-local parent header#1546jasongrout wants to merge 6 commits into
jasongrout wants to merge 6 commits into
Conversation
jasongrout
pushed a commit
to jasongrout/ipywidgets
that referenced
this pull request
Aug 11, 2026
When the shell provides set_thread_parent/reset_thread_parent (ipython/ipykernel#1546), Output.__enter__ delegates the thread-scoped pinning to it: set_thread_parent(parent) on enter (passing the full parent request when one is available, so ip.get_parent() also reflects the capture inside the block, and covering every parent-bearing object the kernel knows about), and reset_thread_parent(tokens) on exit. The direct _parent_header ContextVar pinning is kept as a fallback for ipykernel versions without the API, and everything remains capability-guarded so non-ipykernel kernels are untouched. Verified against real kernels: ipykernel 6.29.5 and 7.3.0 (fallback path) and a kernel built from the ipython/ipykernel#1546 branch (public API path — confirmed via a live probe that each capture block performs exactly one set_thread_parent/reset_thread_parent pair). All real-kernel and mock tests pass on all three; a new mock test pins the API selection, the full-request argument, and the token round-trip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136XmUCLSRfgHrrVw1QYMiW
jasongrout
force-pushed
the
threadlocal-header
branch
from
August 12, 2026 11:02
c2fa718 to
aaceed0
Compare
jasongrout
force-pushed
the
threadlocal-header
branch
from
August 12, 2026 11:53
3b0d52c to
0c10601
Compare
jasongrout
marked this pull request as ready for review
August 12, 2026 23:35
Member
Author
|
@minrk, @krassowski - this finishes out the ideas from #1289 and #1451 to make it easy to set and reset just the thread parent. This will make the OutputWidget's temporary overriding the parent much easier (i.e., helping fix jupyter-widgets/ipywidgets#4020 more cleanly than jupyter-widgets/ipywidgets#4021). I think both of you have the context from #1289 and #1451 to review this? |
jasongrout
force-pushed
the
threadlocal-header
branch
from
August 13, 2026 06:15
9e55212 to
cc87037
Compare
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.
As mentioned in #1289 (comment) and #1451, there should be a public api for setting and clearing a thread-local parent header. This PR creates a recommended public api for setting/resetting a single thread's parent without setting the global fallback header. An ipywidget OutputWidget can use this to temporarily redirect output from a single thread, for example.
Changelog entry:
I also added a number of
x.parent = ...parent setters to be more consistent - I'm not directly going to use those, but happy to remove those if there is an objection.Claude Fable 5 assisted in this PR