【发布时间】:2022-01-23 22:21:46
【问题描述】:
我编写这段代码是为了创建一个无限线程循环,没有重复或中断线程任务。
import threading
import time
thread = None
def loopMyTask():
global thread
if thread is not None and thread.isAlive():
thread.cancel()
thread.join()
thread = threading.Timer(6.0, loopMyTask)
thread.daemon = True
thread.start()
myTask()
def myTask():
# simulate a task
for i in range(14) :
print(str(i))
time.sleep(1)
while True:
loopMyTask()
显然它正在工作,但它返回一个警报
【问题讨论】:
标签: python python-3.x