import time
from threading import Thread
def s_process():
print('***********************************************')
##time.sleep(2)
print('###############################################')
##time.sleep(2)
return
a = Thread(target=s_process)
while(True):
a.start()
a.join()
a.start()
a.join()
为什么这个代码导致错误蟒蛇线程(join()方法而不是等待线程结束?)
***********************************************
###############################################
Traceback (most recent call last):
File "xxxxxxxxxxxxxxxxxxxxx", line 16, in <module>
a.start()
RuntimeError: threads can only be started once
应该不会加入()等到线程完成。如果我有误解怎么加入()的作品,我应该如何等待线程不使用超时
你的代码改成这样 ** 而(真): 一个线程=(目标= s_process) a.start() a.join() ** – Stack
的错误不是在'加入'行,它在'start'行。对我来说这似乎不言自明:不要在同一个对象上调用两次'start'。如果必须创建一个新的线程对象。 – Kevin
您只定义了1个线程'a',并且您已经开始并称其为join()方法。不能再次启动它! – pstatix