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

Skip to content

[Bug]: Figure options with qt backend causes figure to freeze #22200

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

Closed
mrclary opened this issue Jan 11, 2022 · 5 comments
Closed

[Bug]: Figure options with qt backend causes figure to freeze #22200

mrclary opened this issue Jan 11, 2022 · 5 comments
Milestone

Comments

@mrclary
Copy link

mrclary commented Jan 11, 2022

Bug summary

The figure options modal window causes the figure to freeze.
Similar to #18965.

Code for reproduction

  1. Launch jupyter qtconsole
  2. execute code
In [1]: %matplotlib qt5

In [2]: from matplotlib.pyplot import plot

In [3]: plot([1, 2, 4])
Out[3]: [<matplotlib.lines.Line2D at 0x22b15172988>]

In [4]: 
  1. Click on "Edit axis, curve and image parameters"
  2. In qtconsole, execute
import sys
  1. Back at the plot properties window, click "OK"
  2. Now the figure is frozen and it cannot be closed.

Actual outcome

Figure is frozen.

Expected outcome

Figure is not frozen.

Additional information

I've tested in matplotlib 3.4.3 and 3.5.1

Operating system

macOS 11.6.2

Matplotlib Version

3.5.1

Matplotlib Backend

Qt5Agg

Python version

3.7.6

Jupyter version

IPython          : 7.31.0
ipykernel        : 6.6.1
ipywidgets       : not installed 
jupyter_client   : 7.1.0 
jupyter_core     : 4.9.1 
jupyter_server   : not installed 
jupyterlab       : not installed 
nbclient         : 0.5.9 
nbconvert        : 6.4.0 
nbformat         : 5.1.3 
notebook         : not installed 
qtconsole        : 5.2.2 
traitlets        : 5.1.1

Installation

conda

@mrclary
Copy link
Author

mrclary commented Jan 11, 2022

So all the symptoms reported in #18965 are still present, so it would seem that #18966 did not resolve #18965. The symptoms are also present at least as far back as matplotlib 3.3.4.

@tacaswell
Copy link
Member

I can reproduce this, and note that trying the same thing with an IPython shell you can not type while the curve window is open (but it burns a full CPU!), and the figure is live when you hit ok.

In qtconsole it make all Qt windows created later non-responsive to the mouse and keyboard. You can programtically add things or close it with plt.close('all'), resizing works, but the window manager level close does not work (!!).

My intuition here is that somehow the inputhook has been broken (which fits with "no event loop running when idle -> no mouse/keyborad") but that does not fit with resizing working. We are now using dia.show() which, if I recall correctly, creates a new EventLoop object internally, uses that to keep Qt spinning, but does not return from the function that is connected to the signal from the button to open the dialog until after it is closed. The inputhook for Qt also runs an EventLoop rather than the Qt main loop (and on Linux/OSX stops it when a key is pressed and on windows runs it for a short time and then stops it, checks for input, and then re-runs it). My suspicion is that this is something to do with an EventLoop running in an EventLoop with the outer EventLoop being stopped, a new event loop being started, and something becoming orphaned.

The above story makes sense why it works (but you can not type) in the IPython prompt (except for burning CPU) because the dialog window is running its event loop, the signal fires to tell the eventhook event loop to exit, it gets scheduled to be done as soon as the outer event loops gets to process the next event. It is not until that happens that the keys strokes make it to prompt toolkit and get echoed to screen.

I do not know how the qtconsole's integration with Qt works off the top of my head so I am going to speculate a bit. Given that it launches an application, I assume that the QApplication is running its event loop (via exec), the terminal is hosted by the QApplication (not the other way around like in IPython). This is why you can type at it while the window is open (because the keystrokes go to Qt and are then routed back to python, there is an event loop running so Qt handles the keys). Something about this is where things are going sideways.

Sorry for the very rambling comment, I'm thinking out loud.

@impact27
Copy link
Contributor

impact27 commented Jan 11, 2022

This is fixed by #22202

@mrclary
Copy link
Author

mrclary commented Jan 11, 2022

I can confirm #22202 fixes this issue for me.

@oscargus
Copy link
Member

oscargus commented Jun 4, 2022

Closing this as #22202 seems to have fixed it for several persons (including me).

@oscargus oscargus closed this as completed Jun 4, 2022
@tacaswell tacaswell added this to the v3.5.2 milestone Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants