Skip to content

register IPython's eventloop integration in plt.install_repl_displayhook #6734

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

Merged
merged 1 commit into from
Jul 16, 2016

Conversation

minrk
Copy link
Contributor

@minrk minrk commented Jul 13, 2016

Registers eventloop integration for IPython on setup, avoiding hangs when IPython hasn't been told about matplotlib prior to plotting.

The IPython kernel (notebook, qtcosole) has always needed this to avoid hangs if plotting happens prior to %matplotlib magic, but it was less important for terminal IPython < 5.0. Terminal IPython 5.0's adoption of prompt_toolkit means that it has the same eventloop requirements of the kernel, so it's now important in both contexts to avoid hangs.

cc @tacaswell

@jenshnielsen jenshnielsen added this to the 2.0 (style change major release) milestone Jul 13, 2016
# trigger IPython's eventloop integration, if available
from IPython.core.pylabtools import backend2gui

ipython_gui_name = backend2gui.get(get_backend())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do with backends that ipython can not map to a name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing. Since it's a get from a dict, gui_name will be None and it will take no further action, which can be interpreted as either:

  1. IPython doesn't know how to integrate with the eventloop for the given backend, or
  2. it doesn't need to (e.g. Agg)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 right. Thought that backend2gui.get was something much more complicated.

@jankatins
Copy link
Contributor

Closing and reopening to run with miktex changes on appveyor to see if that lets the appveyor tests pass.

@afvincent
Copy link
Contributor

For information, for the moment mpl is quite unusable with IPython 5 when using an interactive session.
For example, on my computer (Linux OS), both with mpl 1.5.1 and 2.0.0b2.post1762+gcf24e05, when doing

import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure()

I have to use Ctrl + D to make the new figure to appear… Morevoer, if I answer n to the prompt, and then want to close the figure window, I have to force its halt (through my DE, Xfce) and IPython is also brutally halted…

The issue doesn't not occur when I don't use an interactive session, and call plt.show() instead.

@tacaswell
Copy link
Member

@afvincent just run %matplotlib, this has always been the recommendation of both mpl and IPython. That it was ever working with out the magic was an implementation detail of the GUI toolkit integrations.

@tacaswell
Copy link
Member

The windows failure looks tex related.

@afvincent
Copy link
Contributor

afvincent commented Jul 15, 2016

@tacaswell : thank you, with the magic command, everything is fine. It seems that I never looked carefully enough to the docs to notice the lines about using %matplotib

@jankatins
Copy link
Contributor

The windows failure looks tex related.

Seems that the fix in master isn't picked up here :-/

registers eventloop integration for IPython on setup,
avoiding hangs when IPython hasn't been told about IPython
prior to plotting.
@minrk minrk force-pushed the ipython-eventloops branch from 7ca197d to 09e4e62 Compare July 16, 2016 06:34
@tacaswell
Copy link
Member

pep8 that is definitly not @minrk 's fault, merging as-is.

@tacaswell tacaswell merged commit e940795 into matplotlib:master Jul 16, 2016
tacaswell added a commit that referenced this pull request Jul 16, 2016
MNT: register IPython's eventloop integration in plt.install_repl_displayhook
@tacaswell
Copy link
Member

backported to v2.x as a61f763

@tacaswell
Copy link
Member

tacaswell commented Sep 8, 2016

cherry-picked back to 1.5.x as 44c206b

tacaswell added a commit that referenced this pull request Sep 8, 2016
MNT: register IPython's eventloop integration in plt.install_repl_displayhook
@QuLogic QuLogic added this to the v1.5.x milestone Sep 9, 2016
@QuLogic QuLogic removed this from the 2.0 (style change major release) milestone Sep 9, 2016
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

Successfully merging this pull request may close these issues.

7 participants