two questions about thread

Bryan Olson fakeaddress at
Sat Jan 14 17:37:00 EST 2006

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?


More information about the Python-list mailing list