How to Restart a thread
many_years_after
shuanyu at gmail.com
Sat Nov 25 10:14:20 EST 2006
class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)
def run(self):
print 'i am running'
print 'i quit run()'
thread = mythread('1')
thread.start()
print threading.activeCount() ## 1 , this means the thread is active
if not thread.isAlive():
print 'i am dead,you can restart' ### OK, this is executed. this
means the thread is no alive
thread.start() #### " thread already started "
This program presentes that the thread quit the *run()* func and is
active but not alive. How to understand this? It is said if the
thread quit the *run()* func , it's dead.
how to restart it ?
Thanks
More information about the Python-list
mailing list