[英]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.