事情是我想殺死當前正在運行的所有線程。例如,我有一個按鈕,它調用了for循環。突然間我想阻止它。python線程以最好的方式終止或終止
這裏是我的代碼:
class WorkerThread(threading.Thread):
def __init__(self,t,*args):
super(WorkerThread,self).__init__(target=t,args=(args[0],args[3]))
self.start()
self.join()
我的實現:
def running(fileopen,methodRun):
#....long task of code are here...
for file in fileTarget:
threads.append(WorkerThread(running,file,count,len(fileTarget),"FindHeader"))
設置鎖定線程的執行單元,不久以後,您可以更改標誌的狀態,讓線程完成其運行一個布爾標誌方法乾淨.... –
嗨,先生,謝謝你的建議,你可以顯示一些代碼來處理? 2到4行代碼將會執行。 – iamcoder
[有什麼辦法可以殺死Python中的線程?](http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python) –