[Python-Dev] Where to put the interrupt module?

Just van Rossum just@letterror.com
Fri, 13 Jun 2003 11:03:36 +0200


Kevin Jacobs wrote:

> On Thu, 12 Jun 2003, Guido van Rossum wrote:
> > > 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.
> 
> True -- I am of the opinion that threads should be cooperatively
> stoppable, but not preemptively stoppable, if that makes sense. 
> Asynchronous exceptions are the ideal way of implementing this, since
> the main interpreter loop is essentially already instrumented to
> handle them.

Exactly.

> > Also, this mechanism can *only* interrupt the main thread.  (That's
> > even true of the more generalized version you were thinking of.)

I wonder if that limitation would be liftable? Anybody interested in
persuing this with me?

> Ah.. that sounds familiar.  I knew there was a reason I didn't pursue
> this avenue farther last time I poked through that code.

Same here. The code that checks for interrupts explicitly does nothing
when called from a thread that's not the main thread.

Naming: putting this into main sounds just right, but I would suggest to
call it sys.interrupt() instead of sys.interrupt_main(). That way *if*
we ever add the possibility to interrupt a non-main thread,
sys.interrupt() could grow an optional argument specifying the thread.

Just