How to stop program when threads is sleeping

Carsten Haese carsten at uniqsys.com
Tue Dec 26 07:57:18 EST 2006


On 25 Dec 2006 21:50:15 -0800, many_years_after wrote
> While , there is something wrong in my expression. What I mean is the
> thread will wait some time after doing some tasks. I want to know is
> there any method to end the thread or make it out of execution of
> waiting. I use time.sleep() to let the thread wait. 

We can't help you if you don't tell us what you need. It's still not quite
clear what exactly you need, but one thing you should know is that you can't
stop a thread while it's sleep()ing, so using sleep() is probably the wrong
approach.

The wait() method of the threading.Event object from my previous response can
take an optional timeout argument. This will make your thread wait until the
timeout elapses or until the event is .set() by another thread, whichever
comes first.

Hope this helps. If this doesn't help, please tell us exactly what you need
and maybe show us some code.

Carsten.




More information about the Python-list mailing list