[Python-Dev] Where to put the interrupt module?
Guido van Rossum
guido@python.org
Thu, 12 Jun 2003 16:51:45 -0400
> In that past, there have been a few times where it would have been
> very convenient to terminate/signal another thread by posting an
> exception to it. Using KeyboardInterrupt to do so is okay, although
> it seems like something of a kludge.
This gets into the general discussion about whether threads should be
stoppable.
Also, this mechanism can *only* interrupt the main thread. (That's
even true of the more generalized version you were thinking of.)
> Code that gives special status to KeyboardInterrupt doesn't worry me
> at all. What I am wary of is code that is not written to be
> exception safe in the presence of unexpected exceptions (not just
> asynchronous ones). The example I was working on yesterday involved
> KeyboardInterrupts generated from an SSL socket in httplib's SSL
> readline method. A keyboard interrupt will result in data read from
> the socket and then stored in a local variable to be lost. Of
> course, this error wasn't very likely before I patched the SSL
> module to check for interrupts, but that is beside the point.
That's a problem that'll always remain.
--Guido van Rossum (home page: http://www.python.org/~guido/)