이 코드를 가지고 :스레드를 다시 시작할 수 있습니까?
def runner1():
os.system('python something.py')
..... and so on
thread_run_1 = threading.Thread(target=runner1, args=[])
....
i =0
j = 0
while i < 2: # i want to run continuously, dont want to use cron jobs
print "while 1"
#i made it simpler, but here are a lot of checks
while j == 0:
print "while 2"
thread_run_1.start()
......
time.sleep(3600)
break
print "back to while 1"
i+=1
print i
그것은이 오류를 방지 할 수있다 : RuntimeError: threads can only be started once
를?
왜 새 스레드를 만들 수 없습니다와 같은 구조라고 생각하지 않는다 자바보다 Runnable 또는 callables 비슷한을 찾기 위해 노력하는 경우? – bereal
@bereal True. 하지만 코드에서 직접 가능한지 알고 싶었습니다. – MikeT
"코드에서 직접"의미하는 것은 무엇입니까? 코드에서 직접 새 스레드를 만듭니다. 파이썬 스레드는 OS 스레드 주변의 씬 래퍼이므로 스레드가 중지되면 더 이상 존재하지 않습니다. 생명의 베레모는 평화롭게 휴식을 취합니다. 그것은 전 스레드입니다. 새 것을 시작하십시오. – bereal