12

I'm getting inconsistent responses from the Keyboard interrupt Ctrl+C in interactive python (run in xterm) after plotting from matplotlib.

As expected, when executing Ctrl+C inside ipython2 I get the KeyboardInterrupt message.

However, once I plot anything using matplotlib (specifically matplotlib.pyplot) Ctrl+C will exit the interactive python session, as opposed to exiting the running script in the interactive python session (if there is one).

A primitive example.

import numpy as n
import matplotlib.pyplot as m
x = n.linspace(0,4*n.pi,500)
y = x**2*n.sin(x)

m.plot(x,y)
m.show()

Preferrable behavior would be for Ctrl+C to always only interrupt a running script (if any is running), instead of the interactive python session itself.

Abstracted
  • 390
  • 3
  • 14
  • 2
    What does "ran any script from ipython2" mean? – user2864740 Aug 11 '14 at 10:22
  • @user2864740 I attempted to edit for clarity. Essentially I meant that phrase as "executing any script I have written (using 'run script.py') from inside an interactive python session". – Abstracted Aug 11 '14 at 10:35
  • possible duplicate of [How to interrupt a runaway ipython evaluation without terminating the parent process?](http://stackoverflow.com/questions/14838061/how-to-interrupt-a-runaway-ipython-evaluation-without-terminating-the-parent-pro) – WBAR Aug 11 '14 at 10:46
  • possible duplicate of http://stackoverflow.com/questions/14838061/how-to-interrupt-a-runaway-ipython-evaluation-without-terminating-the-parent-pro – WBAR Aug 11 '14 at 10:47
  • possible duplicate of [Is there a way to detach matplotlib plots so that the computation can continue?](http://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue) – Dunes Aug 11 '14 at 11:00
  • If people are still researching this problem (like me) then the links in the comments above suggest the following answer : `m.show(0)` or `m.show(block=Flase)` – champost Aug 31 '16 at 00:55

1 Answers1

8

I did have the same problem for a long time. Try to run ipython with qt:

ipython --matplotlib=qt
Will Vousden
  • 32,488
  • 9
  • 84
  • 95
JeanPijon
  • 147
  • 7