[Python-ideas] IDEA: do not alter default SIGINT handling

Stephen J. Turnbull stephen at xemacs.org
Mon Sep 14 03:23:14 CEST 2009

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.

The problem here is that when you return from the signal handler,
you're trapped inside a poorly-written (for this purpose) C extension,
and Python never gets to check for the first quit, let alone repeated
ones.  In Emacs it's pretty rare to get those, because Emacs is quite
hostile to third-party C extensions, so C code QUIT-ified by the
maintainers before it's allowed to be added.  Python has lots of C
extensions, and some are going to need QUIT occasionally -- but not
often enough for the extension maintainer to notice and handle it. :-P

More information about the Python-ideas mailing list