异步高分辨率定时器
aiotimer的Python项目详细描述
与异步兼容的周期计时器。仅限Linux,而且是Alpha API。
示例
计时器被实现为一个简单的协议,类似于 异步的网络协议被处理:
classMyTimer(aiotimer.Protocol):def__init__(self):self.counter=0deftimer_started(self,timer):self.timer=timerdeftimer_ticked(self):# Callback triggered when the timer interval elapses...deftimer_overrun(self):# Callback triggered if the timer_ticked callback runtime# should exceed the timer interval. Return True to# reschedule, otherwise the timer is aborted.returnTruedeferror_received():...
然后可以使用协议创建新计时器:
# Schedule once every 10th of a secondaiotimer.create_timer(MyTimer,0.1,loop=loop)