Skip to content

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

Closed

Description

@fperez

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.

Activity

  1. bfroehle commented on Dec 15, 2011

    @bfroehle
    Contributor

    git bisect points to a0e0692

  2. minrk commented on Dec 15, 2011

    @minrk
    Member

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

  3. fperez commented on Dec 15, 2011

    @fperez
    MemberAuthor

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

  4. minrk commented on Dec 15, 2011

    @minrk
    Member

    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.

  5. fperez commented on Dec 15, 2011

    @fperez
    MemberAuthor

    Pinging @cboos for thoughts on this one...

  6. juliantaylor commented on Dec 16, 2011

    @juliantaylor
    Contributor

    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
    
  7. Carreau commented on Dec 16, 2011

    @Carreau
    Member

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

  8. juliantaylor commented on Dec 16, 2011

    @juliantaylor
    Contributor

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

  9. isofer commented on Jan 12, 2012

    @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

  10. fperez commented on Jan 12, 2012

    @fperez
    MemberAuthor

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

  11. isofer commented on Jan 12, 2012

    @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]: 
    
    
  12. fperez commented on Jan 12, 2012

    @fperez
    MemberAuthor

    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.

  13. minrk commented on Jan 12, 2012

    @minrk
    Member

    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.

  14. fperez commented on Jan 12, 2012

    @fperez
    MemberAuthor

    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.

  15. minrk commented on Jan 12, 2012

    @minrk
    Member

    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.

  16. fperez commented on Jan 12, 2012

    @fperez
    MemberAuthor

    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.

  17. isofer commented on Jan 15, 2012

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

  18. fperez commented on Jan 16, 2012

    @fperez
    MemberAuthor

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

  19. minrk commented on Jan 16, 2012

    @minrk
    Member

    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.

  20. isofer commented on Jan 17, 2012

    @isofer

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

  21. jclevesque commented on Aug 16, 2012

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

  22. keflavich commented on Jun 21, 2014

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

  23. added a commit that references this issue on Nov 3, 2014
    bbaf3c0
  24. maxnoe commented on May 9, 2015

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions