Ticket #110 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

ctrl-C behaviour

Reported by: jdpipe Assigned to: fperez
Priority: normal Milestone: 0.9.0
Component: ipython Version:
Severity: normal Keywords:
Cc:

Description

I just had to write and say that the ctrl-C behaviour in ipython is one of those very small but quite annoying usability things that's been starting to get to me :-)

The particular situation is that I am on a command-line, and I type half of a command, then I change my mind. In any other shell-type tool, I would be able to type ctrl-C to cancel my input and start a new line.

But this doesn't work in ipython. Instead it says KeyboardInterrupt? - Press <Enter> to continue. And I can't use ctrl-C to make that go away either.

Couldn't this KeyboardInterrupt? thing be disabled while the user is actually entering stuff?

Change History

01/12/07 23:21:53 changed by jdpipe

I should add that iPython is in so many other ways a shining example of how to implement a really great command line interface. All the tab completion, docstring tricks, etc, etc, are all great.

03/22/07 02:07:01 changed by fperez

  • status changed from new to assigned.

Sorry, I hadn't noticed this ticket was open.

Are you using ipython with one of the threading flags (-wthread, -qthread, -gthread or -pylab)? If so, there is unfortunately nothing I can do, since Python has no mechanism for asynchronous, cross-thread exceptions.

With a normal ipython (no thread support), I don't see this behavior. On my laptop, hitting Ctrl-C immediately does cancel the line I was on and gives me a new prompt:

In [1]: line to be cancelled...
KeyboardInterrupt

In [1]: print 'all ok'
all ok

If you are seeing problems and you are not using the threading flags, please:

  • Update to ipython SVN to see if that helps.

  • If it doesn't, please give me more details about your OS, python version, etc.

03/22/07 02:09:34 changed by fperez

  • milestone set to 0.7.4.

04/02/07 01:24:19 changed by fperez

  • status changed from assigned to closed.
  • resolution set to fixed.
  • milestone changed from 0.7.4 to 0.9.0.

Closing: I don't see this behavior and no more info is forthcoming from original submitter.

Reopen with the information requested above if necessary. Keep in mind the note about the problem not being fixable in the threaded shells, due to fundamental OS/Python limitations about multiple threads and signal handlers.

04/02/07 01:38:26 changed by jdpipe

  • status changed from closed to reopened.
  • resolution deleted.

Hi there

Didn't receive any notification until this last message, for some reason.

I am seeing this problem with IPython 0.7.2. You are right in thinking that it only occurs in the presence of a threading module; in this case '-pylab'. There *may* still something that could be done for that case though: where the "Press enter to continue" prompt is shown, it would be good if another press of ctrl-C would clear that warning. At present, ctrl-C just causes that warning to appear again. Can you trap the ctrl-C keypress at that prompt? This would be a cosmetic thing that would help usability quite a bit for pylab users.

Cheers JP

04/02/07 02:01:43 changed by fperez

No, the problem is that when threads are present, I can't trap the signals at all in the thread where user code is running.

Furthermore, in a line-oriented program (such as ipython), there is no way to clear a previously written line. Something like that can be done if running in a GUI, or even using curses in a terminal, but not in a purely line-driven program, since the state of previous lines is gone once they've been printed.

It's a bummer, and this is the main reason why I continue to use Tk as my pylab backend (it doesn't need threads because python manages its mainloop in a single thread). But basically, python, multiple threads and asynchronous signals are kind of a toxic mix. I've read a LOT of discussions over the years on this problem, and repeatedly all I get from core python developers is that there really isn't much that can be done in this context.

I'm always on the lookout for new ideas, so if you know of a possible solution for this problem, I'd be delighted to try it out. But believe me, the current situation isn't sub-optimal for lack of trying, unfortunately.

05/10/07 01:27:27 changed by fperez

  • status changed from reopened to closed.
  • resolution set to fixed.

Closing: as of 0.8.0, we do have support for Ctrl-C in the presence of threads. Finally!