KeyboardInterrupt

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Dec 10 21:56:13 EST 2009


En Thu, 10 Dec 2009 20:43:48 -0300, mattia <gervaz at gmail.com> escribió:
> Il Thu, 10 Dec 2009 23:10:02 +0000, Matthew Barnett ha scritto:
>
>> Only the main thread can receive the keyboard interrupt.
>
> Ok, so is there any way to stop all the threads if the keyboard interrupt
> is received?

If all other threads (except the main one) are "daemon" threads, then the  
whole process finishes when the main thread exits; all daemon threads are  
abruptly finished. Note that "try/finally" blocks are not honored, neither  
are "with" statements...

If you want an orderly retreat, the other threads must cooperate (e.g. the  
main thread sets a flag and they periodically check for it).

-- 
Gabriel Genellina




More information about the Python-list mailing list