thread help

Roger Binns rogerb at rogerbinns.com
Wed Jun 16 17:32:08 EDT 2004


Peter Hansen wrote:
> I didn't think things worked quite that way in Java.  For
> example, I thought InterruptedException was seen by a thread
> only if it had actually been asleep at the time it was sent.
>
> I also didn't know it would actually terminate certain
> blocking calls, such as in socket stuff.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#interrupt()

As is the Java way, they have different types of interrupted
exceptions and sockets etc would need to be InterruptibleChannels.
They also use checked exceptions which makes life a lot harder.

More on Java best practises for thread interruption:

http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

I would just settle for a nice clean mechanism whereby you can
call Thread.interrupt() and have an InterruptException in that
thread (which ultimately terminates the thread if it isn't
handled anywhere).

Some threads won't be interruptible because they are deep in
extension libraries.  Perhaps that can be returned to the
caller of Thread.interrupt().

Roger





More information about the Python-list mailing list