Uh oh!
There was an error while loading. Please reload this page.
Fix matplotlib eventloops - #1458
Conversation
d04171a to
230d5b6Compareianthomas23
commented
Oct 20, 2025
Confirmed by OP in #1454 that this fixes the issue. |
Uh oh!
There was an error while loading. Please reload this page.
minrk
commented
Oct 20, 2025
Awesome work, thanks for tackling this! |
jeandet
commented
Nov 4, 2025
@ianthomas23 , we are using that 'do_one_iteration' function inside our app , if you have any hint on what we should use instead (we need an in process kernel), that would be awesome. |
pauldmccarthy
commented
Nov 13, 2025
FWIW I have also been using |
pauldmccarthy
commented
Nov 13, 2025
@jeandet and anybody looking for an alternative - it appears that calling |
ianthomas23
commented
Nov 13, 2025
No, that is not always the correct stream to flush. Using |
pauldmccarthy
commented
Nov 13, 2025
@ianthomas23 Thanks - I don't envisage ever using sub-shells in my application, so for me it looks like |
jeandet
commented
Nov 15, 2025
@ianthomas23 , @pauldmccarthy , thank you for your help, |
This fixes the use of GUI toolkit eventloops for Matplotlib plots in downstream libraries such as
jupyterlab,qtconsoleandjupyter-consolewhich was broken in the 7.0.0 release. Fixes#1454. Here is a video of it in action:mpl-qt.mp4
The primary change is to ensure that the event loops look for jupyter messages on the correct stream, which isn't necessarily the
shell_stream. But I have also removed various functions (do_one_iteration,process_one,dispatch_queueetc) that passed messages to a shell via a message queue and ensured that only one was processed at a time. This functionality is now achieved by theasyncio_lockinshell_mainand the zmq sockets queue the messages for this without specific extra queues. This in-process kernel tests that were using thedo_one_iterationcode path now use theasyncio_lockroute, the same as the subshell-supporting full kernels. AFAICT no downstream libraries explicitly use this old code anyway.I've implemented the fix for
qt,tk(twice as Windows is different),wxandmacosxeventloops. I've ignored thegtkeventloops asgtk3has been deprecated here for a year and a half, andgtkdoesn't work anyway as the correct name in Matplotlib isgtk4so I assume that nobody has been using this otherwise they would have complained that it is not working.In some situations there are warnings about resources being closed or not being closed when event loops are stopped. These may have been around before, but I don't know. Given that there is work underway in
jupyter_client(jupyter/jupyter_client#1080) it is sensible to wait for that to be finished before looking at similar improvements here and in downstream libraries likeqtconsole.