Skip to content

Ctrl-C not clearing prompt in terminal (with EPD?) #625

Closed

Description

@takluyver

As reported by EPD users on the mailing list, Ctrl-C no longer works to clear a prompt in the terminal. One user has apparently tried this with a newer checkout from git, but sees the same problem. This has affected one Linux and one Windows user, but I can't replicate it on Linux.

Expected behaviour:

In [1]: cd something_wrong
KeyboardInterrupt
In [1]:

N.B. It seems Ctrl-C does still work to interrupt running commands.

Activity

  1. jonovik commented on Jul 26, 2011

    @jonovik

    The Pylab shortcut installed by EPD is somewhat intricate. I've tested how Ctrl-C behaves when starting with a plain "ipython". This is on Windows 7 64-bit, EPD 7.1 with Python 2.7.2 and IPython 0.11.dev (2011-07-26).

    Ctrl-C does give the expected KeyboardInterrupt message, but in fact leaves you at a Windows cmd.exe command line. Strange things happen with the process tree in the task manager, and with the processing of console input. To reproduce:

    1. Starting the Windows command line

    Winkey-R (Run) > cmd
    The process explorer now shows "explorer.exe > cmd.exe".

    2. Starting IPython

    C:\temp\testing>ipython
    Python 2.7.2 |EPD 7.1-1 (64-bit)| (default, Jul 3 2011, 15:34:33) [MSC v.1500 64 bit (AMD64)]
    IPython 0.11.dev -- An enhanced Interactive Python.

    The process explorer now shows:
    explorer.exe
    cmd.exe
    ipython.exe
    python.exe

    3. Press Ctrl-C

    In [1]: ^C
    C:\Users\jonvi>
    KeyboardInterrupt
    In [1]:

    The process explorer now shows:
    explorer.exe
    cmd.exe
    python.exe
    ...as if ipython.exe was killed, orphaning the python.exe process.

    4. Stuck in cmd.exe

    Although the prompt looks innocuous at first, input actually goes to cmd.exe:
    In [1]: 2+2
    2+2 is not recognized as an internal or external command, operable program or batch file.
    C:\Users\jonvi>

    5. exit

    One might try to "exit" cmd.exe. This sometimes works (but see below), leaving the process explorer showing:
    explorer.exe
    python.exe

    Pressing Enter again returns to IPython (python.exe, not ipython.exe) and stuff works normally.
    In [2]: 2+2
    Out[2]: 4
    In [3]: exit
    ...exits normally.

    However, sometimes the input processing of cmd.exe gets erratic:

    C:\Users\jonvi>ipython
    In [1]: ^C
    C:\Users\jonvi>
    KeyboardInterrupt
    In [1]: 2+2
    2+2 gjenkjennes ikke som en intern eller ekstern kommando,
    kjørbart program eller satsvis fil.
    C:\Users\jonvi>
    // On pressing "e", everything back to the last "In [1]:" gets deleted.
    In [1]: exit
    xit is not recognized as an internal or external command, operable program or batch file.
    C:\Users\jonvi>
    // Yes, that's "xit" with no "e".
    // Pressing "e" again deletes everything back to "In [1]:e".
    // Finishing with "xit" gives this:
    In [1]: eexit
    xit is not recognized as an internal or external command, operable program or batch file.
    // Pressing Enter twice gives this:
    In [1]: ee
    NameError: name 'ee' is not defined

    I'm not sure what determines whether keyboard input gets mangled. For a while I thought it had to do with whether I typed anything before Ctrl-C, whether I entered anything before "exit", or whether I waited a little while (to put together this bug report) -- but unfortunately I seem unable to predict which of the two scenarios will happen.

  2. jonovik commented on Jul 26, 2011

    @jonovik

    ipython qtconsole

    Here Ctrl-C on the command line just gets ignored. It works fine for interrupting code, though.
    In [1]: while True: pass
    KeyboardInterrupt:

  3. takluyver commented on Jul 26, 2011

    @takluyver
    MemberAuthor

    On the Qt console, Ctrl-C doesn't do anything while you're entering code. Esc or Ctrl-G will clear the current cell. This is intentional.

    As for the Windows thing, I have no idea. Does the same thing happen outside EPD, e.g. if you run python.exe C:\Path\to\ipython.py? Is ipython.exe something the setup process creates, or something Enthought produce?

  4. epatters commented on Jul 26, 2011

    @epatters
    Contributor

    Actually, Ctrl-C copies when you're entering code in the Qt console, and interrupts when you're executing code. We made Ctrl-C context sensitive as a compromise between the conflicting conventions in GUI and console applications.

  5. jonovik commented on Jul 26, 2011

    @jonovik

    On Tue, Jul 26, 2011 at 4:06 PM, takluyver
    reply@reply.github.com
    wrote:

    On the Qt console, Ctrl-C doesn't do anything while you're entering code. Esc or Ctrl-G will clear the current cell. This is intentional.

    Sounds reasonable, works as advertised.

    As for the Windows thing, I have no idea. Does the same thing happen outside EPD, e.g. if you run python.exe C:\Path\to\ipython.py?

    Huh. As it turns out, "python -m ipython" handles Ctrl-C just fine:

    Microsoft Windows [Versjon 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. Med enerett.
    C:\Users\jonvi>python -m ipython
    Python 2.7.2 |EPD 7.1-1 (64-bit)| (default, Jul 3 2011, 15:34:33)
    [MSC v.1500 64 bit (AMD64)]
    IPython 0.11.dev -- An enhanced Interactive Python.
    In [1]: 2+2
    Out[1]: 4
    In [2]: Pressing Ctrl-C now...
    KeyboardInterrupt
    In [2]: 2+2
    Out[2]: 4
    In [3]: ølkjsadfadfsø
    KeyboardInterrupt
    In [3]:
    In [4]: exit

    Works fine in Pylab mode too:
    c:\Python27\Scripts>python -m ipython --pylab
    Welcome to pylab, a matplotlib-based Python environment [backend: WXAgg].
    In [1]: 2+2
    Out[1]: 4
    In [2]: Pressing Ctrl-C now...Nothing happens
    File "", line 1
    Pressing Ctrl-C now...Nothing happens
    ^
    SyntaxError: invalid syntax

    It does indeed seem that EPD can avoid the weird Ctrl-C behaviour just
    by simplifying their shortcut. I'll post a message to
    epd-users@enthought.com pointing here.

    Is ipython.exe something the setup process creates, or something Enthought produce?

    I'm not sure, and unfortunately I have no convenient way to check. For
    what it's worth, ipython.exe is in the python Scripts directory, which
    is in my PATH.
    c:\Python27\Scripts>dir ipython*
    Innhold i c:\Python27\Scripts
    2011-07-26 13:21 340 ipython-qtconsole-script.pyw
    2011-07-26 13:21 7 168 ipython-qtconsole.exe
    2011-07-26 13:21 327 ipython-script.py
    2011-07-26 13:21 7 168 ipython.exe

    EDIT: There is an ipython.bat too, but that one I wrote myself.

  6. takluyver commented on Jul 26, 2011

    @takluyver
    MemberAuthor

    Thanks, Jon. For now I think it looks like the Ctrl-C behaviour is somehow related to EPD. Let us know what you hear from them.

  7. jonovik commented on Jul 26, 2011

    @jonovik
  8. ijstokes commented on Sep 29, 2011

    @ijstokes

    I'm using EPD 7.1-2 ipython on OS X, and CTRL-C doesn't work for me.

  9. esotericbyte commented on Nov 16, 2011

    @esotericbyte

    I have this problem on windows and am using standard ipython, 0.11 not enthought.
    if i execute ipython from the windows dos like prompt it has this problem but does not when run from the icon i have pinned. I think the windows terminal also receives the interrupt and starts capturing input itself. My guess is that there is some call back to say "i got this one" that is not being made by ipython when it handles the signal.
    I have cywin installed but this happens with and without cygwin enabled.
    Thanks for the tips about using task manager for a fix. I hope to at least save some data!
    I am happy to install from github and test.

  10. minrk commented on Nov 17, 2011

    @minrk
    Member

    The Windows bug of ctrl-C breaking the shell when run from cmd appears to be caused by setuptools when it creates the ipython.exe. If you do python C:\Python27\Scripts\ipython-script.py it seems to avoid the issue.

  11. davidbrai commented on Nov 18, 2011

    @davidbrai

    thanks @minrk ! the ctrl-c bug was driving me crazy.

  12. esotericbyte commented on Nov 20, 2011

    @esotericbyte

    The problem on windows 7 64bit running ipython 0.11 python 2.7 happens when ipython is run directly by typing 'ipython' at the windows or cygwin prompt. Python installed on windows, not through cygwin setup.exe does not know about cygwin so you need to give it the windows path of the script file, but after ipython starts when run from cygwin you are able to use the gnu commands with bang ( !stat file,!ls, !egrep -v '^$|^ *#' myfile.py , etc)

        C:\Python27\python.exe "C:\Python27\scripts\ipython-script.py"
    
    
        /cygdrive/c/Python27/python.exe 'C:\\Python27\\Scripts\\ipython-script.py'
    
  13. Carreau commented on Jul 21, 2016

    @Carreau
    Member

    With this issue being 5 years old, the lack of activity, and all the recent refactor I'll assume this is either fixed, or need a new issue to be reopened.

    Thanks all, and closing to try to keep issue list small.

    Thanks !

  14. modified the milestones: no action, wishlist on Jan 9, 2017
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions