ipython / ipykernel

IPython Kernel for Jupyter
https://ipykernel.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
640 stars 364 forks source link

AnyIO commit breaks Matplotlib display in separate windows #1235

Closed ianthomas23 closed 1 month ago

ianthomas23 commented 5 months ago

With the commit before the AnyIO PR on the main branch (830829fd) and using ipython 8.23.0 and matplotlib 3.8.4, the displaying of Matplotlib plots in separate windows (e.g. with qt backend) using jupyter works fine. With the AnyIO commit (772dfb8a) onwards the plot windows are no longer displayed.

Code to reproduce (I've been using jupyter qtconsole but jupyter lab, etc, all show the same):

%matplotlib qt
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 3, 2])

In ipython the same example works fine.

davidbrochart commented 5 months ago

Probably because of external event loop integration.

ianthomas23 commented 4 months ago

enter_eventloop is only ever called if kernel.eventloop is set at startup:

https://github.com/ipython/ipykernel/blob/a7d66ae2197e0d7471ba160542cf5ff7713084b5/ipykernel/kernelapp.py#L732-L736

If the eventloop is set later, e.g. via %matplotlib qt, it is never called.

Plus there are 7 uses of kernel.shell_stream in eventloops.py and the shell_stream was replaced with shell_port in the AnyIO changes. So evidently this code isn't covered by any ipykernel tests.