Fix: Bind browser close output to creation context#14077
Open
mh105 wants to merge 1 commit into
Open
Conversation
Member
|
I think we'll need a bit more info in the code for the next person to follow. Can you link to some ipython / jupyter docs that talk about this as a potential solution? A quick search turned up ipython/ipython#11565 but maybe there is something better. Also, is this something we should special-case to the matplotlib inline backend? (Or maybe we don't need to because it's harmless on any others?) |
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.
Reference issue (if any)
None
What does this implement/fix?
In Jupyter notebook, closing a second or more
Raw.plot()Qt browser appends itsChannels marked as bad:report to the output of the first browser cell rather than the cell that created that browser. This behavior is a bit counterintuitive, since I expect to see the "Channels marked as bad:" message to appear in the same cell I invoke the function.I asked Codex to look into the issue, and it found that IPykernel associates output with a
ContextVar. A persistent Qt event-loop task will retain the context of the cell that initialized it, so a later close callback runs with an older output parent even though MNE’s logger writes to the currentsys.stdout.Codex proposed a minimal change by capturing
contextvars.copy_context()independently when each MNE browser is created, then runs the existing shared close implementation in that captured context. The change looks good to me.Additional information
Codex-generated tests passed:
3 passed).