How to stop program when threads is sleeping

John Henry john106henry at hotmail.com
Mon Dec 25 10:45:08 EST 2006


many_years_after wrote:
> Hi, pythoners:
>
>       There is a problem I couldn't dispose. I start a thread in the my
> program. The thread will do something before executing time.sleep().
> When the user give a signal to the main thread (such as click the 'end'
> button or close the window), the thread should end it's running. But
> how to end the threading when it's sleeping? I set an flag to the
> thread, but it doesn't work.
>
>       I also thought to put  'time.sleep()'   to the main thread. But I
> think the main thread will not response to user's action because it is
> executing sleep().
>
>      Any ideas?
>      Thanks.

The thread should not "sleep" - just take short "cat naps".  The main
should then set some kind of counter, and the thread check the counter
between naps...




More information about the Python-list mailing list