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

Merged
merged 1 commit into from Jul 16, 2016

Conversation

Projects
None yet
7 participants
Contributor

minrk commented Jul 13, 2016 edited

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

mdboom added the needs_review label Jul 13, 2016

minrk referenced this pull request in ipython/ipykernel Jul 14, 2016

Merged

Make inline the default matplotlib backend #159

@tacaswell tacaswell commented on the diff Jul 14, 2016

lib/matplotlib/pyplot.py
@@ -154,6 +155,13 @@ def post_execute():
_IP_REGISTERED = post_execute
_INSTALL_FIG_OBSERVER = False
+
+ # trigger IPython's eventloop integration, if available
+ from IPython.core.pylabtools import backend2gui
+
+ ipython_gui_name = backend2gui.get(get_backend())
@tacaswell

tacaswell Jul 14, 2016

Owner

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

@minrk

minrk Jul 16, 2016

Contributor

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)
@tacaswell

tacaswell Jul 16, 2016

Owner

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

tacaswell referenced this pull request in syl20bnr/spacemacs Jul 14, 2016

Closed

IPython 5 will cause problems. #6580

Contributor

janschulz commented Jul 15, 2016

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

janschulz closed this Jul 15, 2016

janschulz reopened this Jul 15, 2016

@mdboom mdboom added needs_review and removed needs_review labels Jul 15, 2016

Contributor

afvincent commented Jul 15, 2016

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.

Owner

tacaswell commented Jul 15, 2016

@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.

Owner

tacaswell commented Jul 15, 2016

The windows failure looks tex related.

Contributor

afvincent commented Jul 15, 2016 edited

@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

Contributor

janschulz commented Jul 15, 2016

The windows failure looks tex related.

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

@minrk minrk register IPython's eventloop integration in plt.install_repl_displayhook
registers eventloop integration for IPython on setup,
avoiding hangs when IPython hasn't been told about IPython
prior to plotting.
09e4e62
Owner

tacaswell commented Jul 16, 2016

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

@tacaswell tacaswell merged commit e940795 into matplotlib:master Jul 16, 2016

1 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
coverage/coveralls Coverage decreased (-0.004%) to 70.36%
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

tacaswell removed the needs_review label Jul 16, 2016

@tacaswell tacaswell added a commit that referenced this pull request Jul 16, 2016

@tacaswell tacaswell Merge pull request #6734 from minrk/ipython-eventloops
MNT: register IPython's eventloop integration in plt.install_repl_displayhook
a61f763
Owner

tacaswell commented Jul 16, 2016

backported to v2.x as a61f763

minrk deleted the minrk:ipython-eventloops branch Jul 16, 2016

Owner

tacaswell commented Sep 8, 2016 edited

cherry-picked back to 1.5.x as 44c206b

@tacaswell tacaswell added a commit that referenced this pull request Sep 8, 2016

@tacaswell tacaswell Merge pull request #6734 from minrk/ipython-eventloops
MNT: register IPython's eventloop integration in plt.install_repl_displayhook
44c206b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment