Skip to content
This repository

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

Closed
fperez opened this Issue December 15, 2011 · 21 comments

7 participants

Fernando Perez Bradley M. Froehle Min RK Julian Taylor Matthias Bussonnier isofer Julien-Charles Lévesque
Fernando Perez
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.

Bradley M. Froehle
Collaborator

git bisect points to a0e0692

Min RK
Owner

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

Fernando Perez
Owner

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

Min RK
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.

Fernando Perez
Owner

Pinging @cboos for thoughts on this one...

Fernando Perez fperez closed this in 464cb89 December 15, 2011
Julian Taylor
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
Matthias Bussonnier
Collaborator

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

Julian Taylor
Collaborator

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

Fernando Perez fperez referenced this issue from a commit January 10, 2012
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

Fernando Perez
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]: 

Fernando Perez
Owner
Min RK
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.

Fernando Perez
Owner
Min RK
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.

Fernando Perez
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?

Fernando Perez
Owner

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

Min RK
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

Julien-Charles Lévesque

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.

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.