我有一個線程一個簡單的調用:殺死一個線程不起作用
aThread = threading.Thread(target=singleDriverThread, args=(d[0]))
,然後我開始它(aThread.start)
,當我需要停止線程我做的:
aThread.join()
但線程繼續運行..幫助?
我有一個線程一個簡單的調用:殺死一個線程不起作用
aThread = threading.Thread(target=singleDriverThread, args=(d[0]))
,然後我開始它(aThread.start)
,當我需要停止線程我做的:
aThread.join()
但線程繼續運行..幫助?
線程將繼續,直到贖回singleDriverThread
返回運行。
例子:
如果你調用singleDriverThread
看起來像這樣的代碼將永遠不會停止:
def singleDriverThread():
while True:
# do stuff in eternal loop
pass
但如果singleDriverThread
而不是看起來是這樣的:
def singleDriverThread():
# do stuff
return
那麼調用將返回並且該線程將與您的其他代碼一起加入。
你根本無法停止使用'threading' API,你要實現自己的這個算法的線程。 'join'只是等待線程退出,阻塞當前線程,所以它不會向'aThread'發送任何類型的信號,告訴它終止。 – ForceBru
的可能的複製[有什麼方法殺死在Python主題?(http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python) – Tagc
「加入」不是「殺死」。調用'.join()'只是意味着一個線程會等待另一個線程。 – dsh