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

Brett C. drifty@alum.berkeley.edu
Fri, 13 Jun 2003 16:58:15 -0700


Guido van Rossum wrote:
>>How should dummy_thread be modified?  Something like
>>
>>    def interrupt_main():
>>        raise KeyboardInterrupt
> 
> 
> I don't think dummy_thread needs to support this API.
> 

Well, it does now.  =)  I modified dummy_thread to raise 
KeyboardInterrupt after executing a function passed to start_new_thread 
if interrupt_main is called.  I think this simulates threading a little 
better since, calling this you have no clue how long it will take for 
your code to keep executing so might as well let whatever is running 
finish before the "main" thread gets its exception.

The only issue I see is someone calling interrupt_main and expecting an 
instant raise of KeyboardInterrupt if they are in the main thread. 
Damn, I need to modify the code again.

[A few minutes later...]

OK, done.  If someone thinks this is overblown then just back the 
changes out but I figure the module might as well *try* to simulate 
threads as best as it can without getting too complex.

-Brett