Effect of Ctrl-C on threaded apps

gtalvola at NameConnector.com gtalvola at NameConnector.com
Thu Dec 7 20:40:26 EST 2000


I've noticed that on Windows, Ctrl-C causes a KeyboardException
to be thrown always in the main thread.  But I'm told that on Linux,
the exception can be thrown in ANY of the threads.  Does anyone
have any insight into this?

Also, is there any control over _when_ the Python interpreter will
throw the exception?  I've noticed, for instance, on NT if the main
thread is blocked in a Queue.put() operation on a full queue, and
a KeyboardInterrupt is triggered by a Ctrl-C, the Queue will be
left in a broken state -- the next put() operation will block
forever.  It looks like the KeyboardInterrupt gets thrown whenever the
control returns to the interpreter, and the Queue module lacks the
proper try/finally's to unlock its internal lock in this case.

Basically, is there any way to get more control over this behavior?
I'm using 1.5.2 on NT in case there's a difference.  Ideally, I'd be
able to register a handler for Ctrl-C that would call a function that
I specify, then return control to the application at the same place
it left off without an exception being thrown.

- Geoff


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list