假设在 python Thread 的 run() 方法中,我检查一个标志。如果该标志是 True ,我假设我的线程应该退出已经完成它的工作并且应该退出。
那时我应该如何退出线程?试Thread.exit()
class workingThread(Thread):
def __init__(self, flag):
Thread.__init__(self)
self.myName = Thread.getName(self)
self.FLAG= flag
self.start() # start the thread
def run(self) : # Where I check the flag and run the actual code
# STOP
if (self.FLAG == True):
# none of following works all throw exceptions
self.exit()
self._Thread__stop()
self._Thread_delete()
self.quit()
# RUN
elif (self.FLAG == False) :
print str(self.myName)+ " is running."