Skip to content
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

ipython 5.1 sporadically freezes when matplotlib plots are active #10201

Closed
keflavich opened this issue Jan 25, 2017 · 9 comments
Closed

ipython 5.1 sporadically freezes when matplotlib plots are active #10201

keflavich opened this issue Jan 25, 2017 · 9 comments
Milestone

Comments

@keflavich
Copy link

@keflavich keflavich commented Jan 25, 2017

I've using ipython 5.1 with matplotlib 1.5.1 with the Qt4Agg backend on Mac OS X 10.9.5. There have now been 3 occasions when the ipython terminal froze entirely - it would not accept control-c, control-z, or any command I tried. Quitting the Qt plot windows re-activated the python terminal.

This so far has not affected me the first or second time I've made a plot window, but eventually it seems to affect every ipython session I've started with a plot window.

I upgraded to matplotlib 2.0, and the same thing happened, but this time (now with Qt5Agg as a backend), I get a message:

QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier

After that notification, the entire terminal containing ipython became unresponsive. I think the same message was issued under ipython + matplotlib 1.5.1, but the message only appeared after closing ipython entirely, i.e.:

In [11]:
Do you really want to exit ([y]/n)?
QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier
@takluyver
Copy link
Member

@takluyver takluyver commented Jan 26, 2017

Ping @tacaswell

Have you run a %matplotlib command to integrate the event loops? What backend are you using?

@keflavich
Copy link
Author

@keflavich keflavich commented Jan 26, 2017

No, I did not run %matplotlib in any of these sessions, but I started up ipython with --matplotlib.

The two different cases described above are with Qt4Agg and Qt5Agg backends.

@tacaswell
Copy link
Contributor

@tacaswell tacaswell commented Feb 5, 2017

My naive guess is that something is wrong with the way the eventloops are being hooked together (but only on mac).

@keflavich
Copy link
Author

@keflavich keflavich commented Feb 13, 2017

Is there anything I can do to test that hypothesis or work around it?

@takluyver
Copy link
Member

@takluyver takluyver commented Feb 13, 2017

The code handling Qt event loop integration in terminal IPython lives here:
https://github.com/ipython/ipython/blob/master/IPython/terminal/pt_inputhooks/qt.py

I don't understand what might be going wrong, though.

@tacaswell
Copy link
Contributor

@tacaswell tacaswell commented Feb 13, 2017

Where does the context object come from?

I wonder if there is a race condition between triggering the inputhook, the socket being ready to be read, the notifier being created, and the loop starting?

The story here would be things fail when:

  • inputhook gets called
  • the context file descriptor is ready to be read and then torn down
  • the notifier in created, but is broken due to the previous step (this is the dicey part)
  • the Qt event loop now starts, but the notifier that needs to stop it to let the terminal work again is broken so the loop Qt event loop runs forever.
  • closing all of the plot windows (which should still be responsive to pan/zoom and keyboard inputs?) implicitly stops the event loop, returning control to the terminal

From work with asyncio I have the general impression that select on OSX is wonky (which I assume something related to that is being under the hood here).

I suspect that the fix will be to notice when constructing the notifier fails and not starting the event loop. It might also make sense to also hook up a timer that kills the event loop after ~0.1s?

@takluyver
Copy link
Member

@takluyver takluyver commented Feb 13, 2017

The context object comes from prompt_toolkit.

@tacaswell
Copy link
Contributor

@tacaswell tacaswell commented Feb 17, 2017

who is the right person from prompt_toolkit to loop into this?

@takluyver
Copy link
Member

@takluyver takluyver commented Feb 17, 2017

@jonathanslenders is the author of prompt_toolkit. I'd suspect the error is more likely to be in our qt inputhook code, but maybe he can help us to work it out.

tacaswell added a commit to tacaswell/ipython that referenced this issue Feb 18, 2017
try to reduce race conditions by:

 - connect the exit callback before enabling the notifier (this might
   not matter)
 - only bother starting the event loop if the input is not ready.

closes ipython#10201
@Carreau Carreau added this to the 5.3 milestone Feb 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.