***Stopping a Python Thread***
Greg Weeks
weeks at vitus.scs.agilent.com
Fri Mar 15 14:21:36 EST 2002
Steve Lamb (grey at despair.dmiyu.org) wrote:
: On 15 Mar 2002 12:45:48 -0800, Marc <mnations at airmail.net> wrote:
: > command to try and kill it all. But the thread keeps running and does
: > not stop. How do I kill this thread before it completes?
: You must stop each thread from inside the thread. So have some flag
: somewhere that it can check to see if it needs to shut down early.
Actually, you only need to stop non-daemonic threads. For example, if all
the threads (but the main thread) are daemonic, then calling sys.exit in
the main thread will exit the program. (To make a thread t daemonic,
execute t.setDaemonic(1) before starting the thread.)
Finally, if you *must* rudely exit the program from a non-main thread, you
can use os._exit. You're supposed to avoid this, but ...
Greg
More information about the Python-list
mailing list