Python:同时运行多个计时器

时间:2014-10-19 00:48:22

标签: python timer multiple-instances

我想在循环中创建多个计时器。当循环终止时,应该有多个定时器在运行。如果任何定时器超时,则应调用另一个定时器。 我如何在Python中实现它? 任何帮助将不胜感激。

例如。

for i in (0,6):
   do something
   start timer_i

for i in (0,6):
   if timer_i times out:
       call another function

1 个答案:

答案 0 :(得分:2)

查看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
相关问题