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

Closed
fperez opened this Issue Dec 15, 2011 · 23 comments

Projects

None yet

9 participants

@fperez
Member
fperez commented Dec 15, 2011

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
Member
minrk commented Dec 15, 2011

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

@fperez
Member
fperez commented Dec 15, 2011

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

@minrk
Member
minrk commented Dec 15, 2011

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
Member
fperez commented Dec 15, 2011

Pinging @cboos for thoughts on this one...

@fperez fperez closed this in 464cb89 Dec 15, 2011
@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
Member
Carreau commented Dec 16, 2011

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

@isofer
isofer commented Jan 12, 2012

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
Member
fperez commented Jan 12, 2012

@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
isofer commented Jan 12, 2012

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
Member
fperez commented Jan 12, 2012

On Thu, Jan 12, 2012 at 1:21 PM, isofer
reply@reply.github.com
wrote:

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.

Your reinstallation didn't take: that's still IPython 0.12 from EPD,
while git master reads:

IPython 0.13.dev -- An enhanced Interactive Python.

You may need to edit your easy_install.pth files to remove the
hardcoded path to IPython-0.12, so that a manual installation can
actually work. This is an unfortunate problem in how setuptools was
designed, which is one of the reasons I dislike using it.

@minrk
Member
minrk commented Jan 12, 2012

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
Member
fperez commented Jan 12, 2012

On Thu, Jan 12, 2012 at 3:08 PM, Min RK
reply@reply.github.com
wrote:

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.

I bet you're right; I'm using pyqt and it's fine for me.

@minrk
Member
minrk commented Jan 12, 2012

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
Member
fperez commented Jan 12, 2012

On Thu, Jan 12, 2012 at 3:41 PM, Min RK
reply@reply.github.com
wrote:

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.

I think this last report was on OSX, but probably with the stock
pyside provided by EPD.

@isofer
isofer commented Jan 15, 2012

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
Member
fperez commented Jan 16, 2012

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

@minrk
Member
minrk commented Jan 16, 2012

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
isofer commented Jan 17, 2012

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
MaxNoe commented May 9, 2015

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