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

Skip to content

Commit 936674b

Browse files
committed
FIX: Don't enable IPython integration if not entering REPL.
IPython can also be used to simply run files; when this is the case we are not going to be interactive; and we do not want to enable the eventloop integration. Otherwise someone doing: $ ipython script.py Will simply see a window blink, as IPython will exit immediately instead of showing the window and exit. I'm not quite sure how to test that are we basically _want_ something to block forever and wait for user input; so no test added Closes: ipython/ipython#11837
1 parent 73e2f56 commit 936674b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

lib/matplotlib/backend_bases.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,20 @@ def _draw(renderer): raise Done(renderer)
15531553
return figure._cachedRenderer
15541554

15551555

1556+
def is_non_interactive_terminal_ipython(ip):
1557+
"""
1558+
Return whether we are in a a terminal IPython, but non interactive.
1559+
1560+
When in _terminal_ IPython, ip.parent will have and `interact` attribute,
1561+
if this attribute is False we do not setup eventloop integration as the
1562+
user will _not_ interact with IPython. In all other case (ZMQKernel, or is
1563+
interactive), we do.
1564+
"""
1565+
return (hasattr(ip, 'parent')
1566+
and (ip.parent is not None)
1567+
and getattr(ip.parent, 'interact', None) is False)
1568+
1569+
15561570
class FigureCanvasBase:
15571571
"""
15581572
The canvas the figure renders into.
@@ -1649,9 +1663,13 @@ def _fix_ipython_backend2gui(cls):
16491663
# Work around pylabtools.find_gui_and_backend always reading from
16501664
# rcParamsOrig.
16511665
orig_origbackend = mpl.rcParamsOrig["backend"]
1666+
16521667
try:
16531668
mpl.rcParamsOrig["backend"] = mpl.rcParams["backend"]
1654-
ip.enable_matplotlib()
1669+
if is_non_interactive_terminal_ipython(ip):
1670+
pass
1671+
else:
1672+
ip.enable_matplotlib()
16551673
finally:
16561674
mpl.rcParamsOrig["backend"] = orig_origbackend
16571675

0 commit comments

Comments
 (0)