-
-
Notifications
You must be signed in to change notification settings - Fork 391
Fix routing of background thread output when no parent is set explicitly #1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- removes guessing about whether threads should route output to their originating cell - thread-local value is persisted, if set explicitly - if no thread-local value is set, fallback on a global value (usually the latest cell) There's lots of duplication around, but I couldn't see a way to resolve that without breaking things.
|
passing everywhere but 3.14, includes missing coverage for #1450 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one typo.
ipykernel/kernelbase.py
Outdated
| def _get_shell_context_var(self, var: ContextVar[T]) -> T: | ||
| """Lookup a ContextVar, falling back on the shell context | ||
| Allows for user-launched Threads to still resolve to the shell's mai context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo mai to main ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks. Fixed.
|
The failing qtconsole test is labelled as flaky in qtconsole. The subshells changes in this repo made it more flaky, and it looks this PR might be making it more flaky still. I'd be inclined to merge this as it is, and if the flaky test in too annoying we could just exclude it from CI here until it can be investigated downstream. What do you think @minrk? |
|
That sounds good to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @minrk
|
Just to understand, this made the behaviour from #1186 opt-in rather than opt-out? |
Yeah, but it kind of brings back jupyter-widgets/ipywidgets#2358 and jupyterlab/jupyterlab#3936? I understand the motivation for making it opt-out, and I understand that making it opt-in for now might be easier. If the plan is to release in 7.0.2 I would suggest highlighting this in the release notes, and documenting the workaround of using |
|
Thanks for working on this. When will it be included in a new release? |
|
@krassowski yes, though it is opt-in instead of unconditional, it never was 'opt-out' and since the guess was wrong very often, I think, having a clear opt-in is better than having no opt out at all, which is the choice we were presented with. Getting back to the default behavior once opted in is still a lot trickier than it should be, so room to improve there. jupyter-widgets/ipywidgets#2358 should be addressed by I think having the thread-local state is still a great fix and the right thing to do, it's just the initial guess that was the problem. I think there are still improvements to be made on this front. I 100% agree on documenting the change, I'll look into that. |
|
I've prepared a draft release of 7.1.0 as I realised that #1435 is an enhancement and hence needs to be in a minor not patch release. The draft changelog notes are at https://github.com/ipython/ipykernel/releases; I've written a little summary at the top for the changes but I have not covered this PR. @minrk Would you like to add a line or two of documentation there, or a link to wherever else you're planning to write it? |
|
@ianthomas23 @krassowski Any idea when a new version of IPyKernel will be shipped out with this fix? Thanks for promptly fixing this issue |
|
@ianthomas23 thanks, I added a little note to the 7.1 release notes draft. Good to go from my end once I skip the most failing tests in #1463 |
@DonJayamanne ipykernel 7.1.0 has been released. |
|
@ianthomas23 thanks for shipping this! |
There's lots of duplication around, but I couldn't see a way to resolve that without breaking things. That can be a later goal.
closes #1450
improves but does not quite close #1289 because there is still no explicit opt-out once a thread has set its parent (there is no
clear_parent()), but at least the parent isn't set by default anymore, so the opt-out is less urgently needed.To send a thread's output to a specific cell, this must now be done explicitly, which I think is a big improvement and simplification. No thread inheritance is tracked, no cell guessing occurs.
To route output to a specific cell from a thread, explicitly call
set_parentin the thread with the parent from the outer context that should be kept for the duration of the thread: