python's threading has no "interrupt"?

Dave Brueck dave at pythonapocrypha.com
Tue Dec 2 08:25:21 EST 2003


Jane wrote:
> > >>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
> > >>sleeping/waiting state.
> > >>
> > >>Is there any way of doing this with python's thread? I suppose thread
> > >>interrupt is a very primitive functionality for stopping a blocked
> > >>thread.
> > >>
> > >>
> > >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
[snip]
>
> Thanks, but it doesn't give a solution. The problem is that there can
> be multiple condition variables and I have to interrupt the thread no
> matter what condition variable is waiting.

What's your actual use case (IOW, what programming problem are you trying to
solve)? Maybe there is a Python solution that will work for you, but in order
to help you find it, people here will need to better understand what you're
trying to do.

You've noticed that there isn't an identical construct for what you were doing
in Java, so it may be that the Python way will be a completely different
approach to the problem rather than just a direct conversion from Java to
Python syntax.

-Dave






More information about the Python-list mailing list