相关疑难解决方法(0)

Python threading.timer - 每隔'n'秒重复一次

我对python计时器有困难,非常感谢一些建议或帮助:D

我不太了解线程如何工作,但我只是想每0.5秒触发一次函数,并能够启动和停止并重置计时器.

但是,RuntimeError: threads can only be started once当我执行threading.timer.start()两次时,我会继续得到.有没有解决这个问题?我threading.timer.cancel()在每次开始前尝试申请.

伪代码:

t=threading.timer(0.5,function)
while True:
    t.cancel()
    t.start()
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x

75
推荐指数
6
解决办法
16万
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1