我有一个线程一个简单的调用:杀死一个线程不起作用
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