
On Mon, 14 Sep 2009 10:23:14 +0900, Stephen J. Turnbull wrote:
MRAB writes:
How about 2 (or 3?) in rapid succession ("here's a CTRL-C, and here's another one to show I mean it!" :-)).
That's more complexity than you want to put in a signal handler. The way Emacs handles this is that the signal handler just enqueues a quit event, and the event loop checks for it and handles it. In other places (such as looping functions) more complex QUIT processing (that checks for repeated signals and throws to the innermost QUIT catcher) is done, but this can only be done in "safe" places, not in the signal handler itself. I imagine Python works the same way and it works fine in pure Python programs, too.
A cursory check over the signal handler shows the Python calls PyErr_SetNone(PyExc_KeyboardInterrupt) within the signal handler itself. Handling a double-Ctrl-C would be very trivial, would solve the OP problem, and would not declare all existing C/C++ code in the world as "non-compatible-with-Python-ctrl-c-by-default", which is the current shame we live in. -- Giovanni Bajo Develer S.r.l. http://www.develer.com