-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Stuck figure window after plt.close() in ipython with Qt5 #17109
Comments
If you create another new figure do the existing ones become responsive again? Alternatively dose My suspicion is that with all the windows closed, we are no longer spinning the QT event loop so while the window exists in the display manager side, nothing in handling the input. |
@tacaswell
Unfortunately no, the "closed" figure stays there and still does not respond.
I also had this suspicion, I tried many combinations but what I see is that anytime I created more than one figure, this problem happens some way or the other and it's impossible do close those stuck figures. |
I realized that I was not running the latest stable version, which is 3.2.1. I installed it from conda-forge and I experience the same bug. |
Throwing a This is also a very old bug, which reproduced back to 2.2.5. Possibly it's something to do with IPython versions and its Qt integration. |
This is also not macOS-specific. |
I suspect that there is some race going on between IPython and Matplotlib trying to start up the global QApplication instance (but that is more of a hunch than anything solid). |
I think I found a workaround. I manually connected the qt window destroy function to the figures' close events. My first tests seem to work, either using the pyplot close function, or the window close button (both cases had problems). Maybe it could serve as a direction to solve this bug in the real code.
|
Interestingly, the workaround doesn't work anymore as soon as there's a plt.pause while the figures are shown. Works:
Doesn't work:
There seems to effectively has something with the event loop (I messed a bit with MPL's code and it's the start_event_loop from plt.pause that seems to cause this difference). |
I want to add that I encounter what seems to be a related issue when creating many figures in a script that is run from the command line. While the script does not hang on figures when
Increasing or removing the limit on the number of open files allowed is not an adequate solution for me since this would cause extreme CPU slowdowns from the large number of figures I am creating. VersionsOperating system: macOS 10.15.7 Code for ReproductionRunning as a script from command line.
Adding Current WorkaroundUsing
|
@tfetherolf, this seems somewhat different since its from the command line and never uses an interactive backend, can you open a new issue for this? |
@tfetherolf If you do |
In both cases my new suspicion is that for various reasons we defer setting up the logic to tear down the GUI windows until after the GUI window is shown, however if you close the figure before it is shown we end up in a state where on one hand we have asked a GUI to be shown, then tear down the Python side logic, then the window shows and we get a zombie window (with no Python side way to get a hold of it!) and no logic of when to close it. |
@tacaswell Adding |
doing a This is connected to #18609 (comment) in the sense that we are not sure if "close" means "hide" or "destroy". |
Hello @tacaswell |
Interesting, still suspect it is a fussy reference counting issue, but apparently a platform dependent one... |
@tacaswell was this perhaps fixed by the garbage collection change? |
It seems like the original issue is gone. At least on Windows 11. But since I do not know if it existed on Windows, it is hard to say if it is fixed... |
I can confirm that this is not a problem on linux, but it does still happen on osx (using qt5 from Conda-forge). My current theories are:
I also notice if you use the dock to try and kill the Matplotlib logo app it does not actually close any of the windows (live ones or the zombies), you can not make any more, but python is fine. If you then do @QuLogic where else did you reproduce this? |
Note that you need to do the steps from the first post in a single cell. I can reproduce in my existing conda environment, with Python 3.9, Matplotlib
I cannot reproduce with Fedora system packages:
|
I also went through all iterations of
for X =10:
and for X = 11:
Starting with the 3.10 environment, I could not reproduce the problem. I noticed that qt was coming from I don't know what exactly would have fixed it, but it seems like upgrading everything will do? |
To contradict tacaswell, this does seem to be a problem in linux, it has been happening to me for about 18 months now. plt.figure('hello world') Will leave the window hanging, not everytime, but often enough to be annoying. It closes when I close ipython3. |
I could not reproduces this 5 times in a row with
When this does not work, what is the result of
? Does calling The core of the problem is that when you do @jcl-feritech Can you also give use your mpl version, the exact IPython version, which qt binding you are using and it's exact version, and the version of Qt it is built against? Which window manager you are using and if it is X11 or wayland may also be relevant. |
I am using ipython version 7.31.1, mpl version 3.5.1. Sadly plt.ion() does not fix things. I have realised that I am using TkAgg, not Qt, sorry for the confusion. |
Do you have the same problem with tk in mpl3.8.3 ? |
I am testing mpl3.8.3, and I can't reproduce the problem yet, I will report back here if it breaks in due course. Thank you. |
Bug report
Bug summary
When more than one figure is shown, then clicking on the last figure's close button or running plt.close() or plt.close('all') leaves a zombie figure behind. At first, figure windows are properly closed, but when switching back to the matplotlib python application, the last figure resuscitates and is not clickable nor closable anymore.
Doing the samething another time leaves an additional zombie figure window, and so on. The only way to close those non-responding windows is to quit ipython.
Code for reproduction
Running in ipython:
Actual outcome
No output, and the figures close. But then if we press alt-tab, the last figure resuscitates and does not respond to user input.
Expected outcome
The last figure should not resuscitate.
Matplotlib version
Qt5Agg
):Installation under conda, default conda channel:
[TAC edited to remove comments in example code to make copy-pasting easier]
The text was updated successfully, but these errors were encountered: