two questions about thread

Kevin other at cazabon.com
Sun Jan 15 09:26:04 EST 2006


The best way to do this is by using a flag or event that the child-threads
monitor each loop (or multiple times per loop if it's a long loop).  If the
flag is set, they exit themselves.

The parent thread only has to set the flag to cause the children to die.

Kevin.


"Bryan Olson" <fakeaddress at nowhere.org> wrote in message
news:g2fyf.888$H71.344 at newssvr13.news.prodigy.com...
> iclinux wrote:
> > a.  how to exit the whole process in a thread?
> > b. when thread doing a infinite loops, how to terminate the process?:
>
> As others noted, the threading module offers Thread.setDaemon.
> As the doc says: "The entire Python program exits when no active
> non-daemon threads are left."
>
> Python starts your program with one (non-daemon) thread which
> is sometimes called the "main" thread. I suggest creating all
> other threads as daemons. The process will then exit when the
> main thread exits.
>
> If some other thread needs to end the process, it does so by
> telling the main thread to exit. For example, we might leave
> the main thread waiting at a lock (or semaphore), and exit if
> the lock is ever released.
>
>
>  >     it seems that the follow doesn't work, in my Windows XP:
>  >             thread.start()
>  >             thread.join()
>
> Is that part of the questions above, or another issue?
>
>
> -- 
> --Bryan





More information about the Python-list mailing list