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()
なぜ、このコードはエラーPythonのスレッド(参加()終了するスレッドを待っていない?)
***********************************************
###############################################
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
エラーが上ではありません ' 'join'行では、' start'行にあります。私には自明のようです:同じオブジェクトに対して 'start'を2度コールしないでください。必要がある場合は、新しいスレッドオブジェクトを作成します。 – Kevin
あなたは1つのスレッドだけを定義しています、 'a'とすでに始まっているのは、その' join() 'メソッドです。それをもう一度始める! – pstatix