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

Inconsistent %matplotlib qt behavior #4997

Closed
jabooth opened this issue Feb 2, 2014 · 10 comments · Fixed by #5077
Closed

Inconsistent %matplotlib qt behavior #4997

jabooth opened this issue Feb 2, 2014 · 10 comments · Fixed by #5077
Assignees
Labels
Milestone

Comments

@jabooth
Copy link
Contributor

jabooth commented Feb 2, 2014

Evaluating a cell beginning with the %matplotlib qt magic and immediately following with commands to Mayavi cause the kernel to freeze. The Mayavi window opens correctly and responds to user input, but the cell never yields control back to the user.

If instead, a cell containing %matplotlib qt in isolation is run, it returns without issue. Subsequently issuing Mayavi commands in a separate cell work as expected, returning immediately.

This notebook gives a minimal demonstration of the problem, as well as some further diagnostic information.

Note that the problem is confirmed to exist on OS X on a recent master and on Linux (thanks @fperez)

Note that this bug only occurs the first time the %matplotlib qt command is executed - subsequent calls (e.g. after switching to %matplotlib inline and back to %matplotlib qt with commands immediately following in the qt enabled cell) work fine.

{'codename': 'Work in Progress',
 'commit_hash': '9b8c058',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path':     '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython',
 'ipython_version': '2.0.0-dev',
 'os_name': 'posix',
 'platform': 'Darwin-13.0.2-x86_64-i386-64bit',
 'sys_executable':     '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python',
 'sys_platform': 'darwin',
 'sys_version': '2.7.5 (default, Oct 25 2013, 08:11:09) \n[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)]'}
@fperez
Copy link
Member

fperez commented Feb 2, 2014

It's worth noting that the problem can also be seen from the qt console, so it's not notebook-specific.

@tritemio
Copy link
Contributor

tritemio commented Feb 3, 2014

I experienced a similar behavior trying to open a Qt dialog.

I normally use "inline" but I need to switch to "qt" mode to launch the dialog (otherwise the dialog does not launch).

A while ago I asked a SO question that apparently got unnoticed:
http://stackoverflow.com/questions/20790926/ipython-notebook-open-select-file-with-gui-qt-dialog

I also made a notebook that reproduces the problem:
http://nbviewer.ipython.org/gist/anonymous/8138346

@patricksnape
Copy link

I can confirm this also happens using Matplotlib on current master.

@minrk
Copy link
Member

minrk commented Feb 3, 2014

This is because the kernel eventloop integration happens in between iterations (cell executions), so a blocking call is made between telling the kernel to hook up with the eventloop, and actually handing off control. I think we can improve how that's handled, I will look into it.

@minrk minrk added this to the 2.0 milestone Feb 3, 2014
@minrk minrk self-assigned this Feb 3, 2014
@fperez
Copy link
Member

fperez commented Feb 3, 2014

Great, thanks @minrk

@minrk
Copy link
Member

minrk commented Feb 9, 2014

Can you give #5077 a try? I think it was a pretty basic problem of having two eventloops going at once:

  • reply message is enqueued in the tornado eventloop
  • kernel hands off control to Qt
  • Qt eventloop takes over from tornado
  • tornado never gets to its next iteration, which is when the reply would be sent (indicating to the frontend that it has finished processing)

The change I made in #5077 is to just flush any pending sends when the GUI eventloop is entered, so there shouldn't be any messages waiting in tornado's queue.

@jabooth
Copy link
Contributor Author

jabooth commented Feb 9, 2014

@minrk can confirm #5077 fixes the issue for me on OS X. Thanks! 👍

@ellisonbg
Copy link
Member

@fperez can you review this fix?

@fperez
Copy link
Member

fperez commented Feb 11, 2014

Yup, doing so now...

fperez added a commit that referenced this issue Feb 11, 2014
Flush replies when entering an eventloop. This avoids possible hangs when the GUI eventloop prevents queued replies from being sent.

Closes #4997.
@tritemio
Copy link
Contributor

I updated to 2.0. However the kernel still crashes running the example notebook linked above.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Flush replies when entering an eventloop. This avoids possible hangs when the GUI eventloop prevents queued replies from being sent.

Closes ipython#4997.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants