[英]Python: Running multiple timers simultaneously
我想在循环中创建多个计时器。 当循环终止时,应运行多个计时器。 如果任何计时器超时,则应调用另一个函数。 如何在Python中实现呢? 任何帮助将不胜感激。
例如。
for i in (0,6):
do something
start timer_i
for i in (0,6):
if timer_i times out:
call another function
查看Timer
,它位于python标准库的threading
模块中。 该文档提供以下示例:
from threading import Timer
def hello():
print("hello, world")
t = Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.