python's threading has no "interrupt"?
gandalf at geochemsource.com
Tue Dec 2 10:38:47 CET 2003
>>As far as I know python's threading module models after Java's.
>>However, I can't find something equivalent to Java's interrupt and
>>isInterrupted methods, along with InterruptedException.
>>"somethread.interrupt()" will wake somethread up when it's in
>>Is there any way of doing this with python's thread? I suppose thread
>>interrupt is a very primitive functionality for stopping a blocked
>Well, I haven't got any answer since I posted it. Meanwhile, I have
>been searching for it myself. Something new has been added in 2.3 in
>thread module. That's interrupt_main. But, unfortunately, it is the
>opposite of what I expected; It interrupts the main thread.
>After all this, I am a bit disappointed about Python. (it's sad)
Did you try condition objects? threading.Condition
Example from the library reference:
# Consume one item
while not an_item_is_available():
# Produce one item
You can block a thread with a condition object by calling its 'wait()'
method. You can
call the 'notify()' method from another thread and that will 'interrupt'
the blocked thread.
It is not the very same thing, but I suspect you can use it for the same
More information about the Python-list