Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ctrl-C not working when GUI/pylab integration is active #1157

Closed
fperez opened this Issue · 23 comments

9 participants

@fperez
Owner

As @juliantaylor mentioned in #825, it seems that recently Ctrl-C stopped working. To see it, open a normal ipython; first verify that you can interrupt a normal operation:

In [1]: import time; time.sleep(3)
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/home/fperez/tmp/src/scipy/<ipython-input-1-8d480fb9ac1e> in <module>()
----> 1 import time; time.sleep(3)

KeyboardInterrupt: 

Then turn GUI support on and try again:

In [2]: gui qt
Out[2]: <PyQt4.QtGui.QApplication at 0x2b84f80>

In [3]: import time; time.sleep(3)
^C^C^C
In [4]: 

Above, I hit ^C three times and nothing happened, the time.sleep(3) ran to completion without the interrupt working.

This is new and a major issue we do need to resolve before releasing 0.12.

@bfroehle

git bisect points to a0e0692

@minrk
Owner

The recent attempts to improve Qt behavior had some pretty complex interrupt catching, so presumably that's the cause.

@fperez
Owner

Good hunting, @bfroehle. And the problem is indeed specific to Qt, it doesn't occur with gui wx for example.

@minrk
Owner

Indeed, a0e0692 is responsible in particular, but the interrupt-handling in inputhook_qt4 seems to generally be wrong:

  • ctrl-C at prompt shows error message about interrupting qt loop, and disabling the eventloop, but that's not actually what happens - the qt hook remains registered.update: I misread, the message is accurate, it just looks like an error.
  • ctrl-C during execution is ignored.
If anything, it would appear that the ignore/allow ctrl-C appears to be backwards. If I reverse them, the behavior seems a good deal more sensible: * ctrl-C during prompt is ignored (not great, but not horrible) * ctrl-C during execution behaves normally

PR #1160 simply restores the SIGINT handler outside of the inputhook.

@fperez
Owner

Pinging @cboos for thoughts on this one...

@fperez fperez closed this in 464cb89
@juliantaylor
Collaborator

this change has a nasty side effect when cancelling a reverse history search (^R) with ^C.
You then end up with an empty prompt but if you press return or an arrow key whatever was found in the history appears (and in case of return executed)

>>> print 1
1
>>> ^R pri
(reverse-i-search)`pr': print 1
^C^C
>>> <CR>
1
@Carreau
Owner

>>> ? normal pyhton shell ?
Actually it does that on both IPython and normal python shell for me. And was ther on IPython before this issue

@juliantaylor
Collaborator

indeed this was always the case, I was just did not have ctrl+c available for so long I forgot about this issue.

@fperez fperez referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@isofer

I've just upgraded from ipython 0.11 to 0.12 using easy_install and I started having this issue.
Ctrl-C is not working when GUI support for qt is turned on.
I did not have this issue before.

I'm using OS X 10.6
Python 2.7.2 |EPD 7.1-2 (64-bit)
and I've upgraded to 0.12

thank you

@fperez
Owner

@isofer, just so we're clear: the following doesn't work for you:

In [4]: import time; time.sleep(2)    #### <<<====  HIT Ctrl-C NOW.
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/home/fperez/research/dif-tx/src/phantom/<ipython-input-4-22e572909911> in <module>()
----> 1 import time; time.sleep(2)

KeyboardInterrupt: 

Because it seems to be working fine here for me. Before we reopen this issue, we need to really know under what conditions there's a problem.

Also, please try it with current git master, as there's always a chance something changed between the version in EPD and git master.

@isofer

yes. it does not work for me.
I reinstalled ipython from git master, but I still have this problem.

mrisofer@imri-mbp~/Documents/third: ipython --pylab='tk'
Python 2.7.2 |EPD 7.1-2 (64-bit)| (default, Jul 27 2011, 14:50:45) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Welcome to pylab, a matplotlib-based Python environment [backend: TkAgg].
For more information, type 'help(pylab)'.

In [1]: import time; time.sleep(3)
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/Users/imrisofer/Documents/third/<ipython-input-1-8d480fb9ac1e> in <module>()
----> 1 import time; time.sleep(3)

KeyboardInterrupt: 

In [2]: gui qt
Out[2]: <PyQt4.QtGui.QApplication at 0x10900b560>

In [3]: import time; time.sleep(3)
^C^C^C^C^C^C
In [4]: 

@fperez
Owner
@minrk
Owner

There is a pretty good chance this is a PySide issue. I seem to recall there was some issue working with the inputhook there. For some reason, EPD is still shipping with PySide 1.0.5 that was current in July, and there have been several significant fixes/improvements in the five releases since then.

@fperez
Owner
@minrk
Owner

And I'm using PySide 1.0.7 on OSX without issue as well, so if it is a PySide issue it is linux-specific or fixed since the EPD version.

@fperez
Owner
@isofer

newbie question:
I've download and installed the PySide 1.0.9 package from the official site, but when I open ipython and look at PySide.__version__ it returns 1.0.5
how can I fix this?

@fperez
Owner

You probably still have the 1.0.5 version installed somewhere, you'll need to find and remove that first.

@minrk
Owner

If you are using EPD, it ignores systemwide installs of anything in favor of the ones it ships with, and I assume you used the binary installer of PySide, which does a normal system install.

It's possible you could clobber the one in EPD with the one installed from PySide.org, but that may not work and trying to do it could ruin your EPD such that you have to reinstall it. Though I've been known to do things exactly like this with varying degrees of success (and ruination).

Part of the cost of EPD (or any package-management system for that matter) is added difficulty for using your own versions of things, and 'official' binary installers (other than Python eggs) are rarely compatible.

I'm not sure it's worth trying to get newer PySide running with EPD, but rather bug EPD folks about getting a reasonably current PySide into EPD officially. It's a pretty big deal, especially on OSX where numerous critical bugs have been fixed since 1.0.5.

@isofer

I saw that EPD 7.2.2 comes with PySide 1.1
so that might solve it.
thank you for all your help

@jclevesque

I have PySide 1.1.1, still can't interrupt my scripts when I invoke them directly from command line, e.g. :

ipython --gui='qt' long_test_script.py

Here is the testing script used:

import time
time.sleep(100)

I woud say it's not related with PySide or QT because I can reproduce the problem also using wx as the gui app. However, when I launch ipython by itself, then use %run long_test_script.py command it works. I have problems only when I start execution directly from the command line.

@keflavich

This is an old issue, but I'm seeing it now with the latest conda-installed setup:

ipython --gui='qt' -c "import time; time.sleep(10)"

and control-c just yields ^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C

conda: 3.5.5
qt: 4.8.5 (also tested 4.7.4)
matplotlib: 1.3.1
ipython: 2.0.0, 2.1.0
pyqt: 4.10.4

It is specific to the qt backend; the tk backend works.

@MaxNoe

It seems that this error is back. Using ipython 3, matplotlib 1.4, qt 4.8.6 i get this if I use %matplotlib qt and doing a keyboard interrupt:

 Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
  File "/home/maxnoe/.local/anaconda3/lib/python3.4/site-packages/IPython/lib/inputhookqt4.py", line 90, in inputhook_qt4
    try:
KeyboardInterrupt

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.