Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ianthomas23
Copy link
Member

The upcoming ipykernel 7.0.0 release will support subshells which are separate threads of execution within a kernel process. JupyterLab has already been updated to deal with subshells on kernels that support them and this includes options for running comms over subshells (jupyterlab/jupyterlab#17363). This PR contains changes that are needed in ipympl to support subshells, specifically use of a threading.Lock in the python code that accesses global state such at Matplotlib's Gcf and ipython.display. Without this we see problems such as plots not being displayed as one thread can be, for example, modifying a collection in Gcf whilst another is reading it. Strictly speaking we only need to lock when one thread is writing to a global as we can tolerate multiple non-modifying reads at the same time, but I have preferred to keep the changes as simple and understandable as possible but putting the locks at a high level in each of the functions that needs it.

Screenshot 2025-08-13 at 11 29 40

Above is a screenshot reproducing the problem using latest commit 5e068ed, showing that the third plot is not displayed. To reproduce this use the latest jupyterlab and precisely ipykernel==7.0.0a2, and in Lab's Settings Editor select "Kernel comms over subshells" to be "One subshell per comm-target". It does not occur every time, but this is the setting that I have found most likely to produce the problem. After this PR, all plots display correctly.

Copy link
Contributor

Binder 👈 Launch a binder notebook on branch ianthomas23/ipympl/lock-for-subshells-2

Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@martinRenou martinRenou merged commit 1ef9f67 into matplotlib:main Aug 25, 2025
8 of 9 checks passed
@ianthomas23 ianthomas23 deleted the lock-for-subshells-2 branch September 2, 2025 08:47
@ianthomas23
Copy link
Member Author

We will need a new release of ipympl with this before ipykernel 7.0.0 is released. I think it could be 0.9.8 as this isn't really new functionality, or 0.10.0 is that is preferred.

@martinRenou
Copy link
Member

Sounds good! We can make it 0.9.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants