我想知道如何使用 python 设置计时器。我目前正在使用 select.poll/epoll 并且创建一个 timerfd 将是最简单的方法。
我看到的另一种方式是在循环之后检查我的任何事件是否耗时并执行它们的功能。
其他方法:
import select,time
timeout =0
epoll.register(rpm_file.fileno(), select.EPOLLPRI)
while True:
events = epoll.poll(0)
for fileno,event in events:
#processing fd events...
now = time.time()
if now > timeout:
# timeout events
最佳答案
此答案仅适用于 Linux。
您可以尝试下面的名为 linuxfd 的 python 包,其中包含 timerfd 的包装器:
https://github.com/FrankAbelbeck/linuxfd
它由 python 包索引索引:
https://pypi.python.org/pypi/linuxfd/1.4.4
作者的一些例子:
https://abelbeck.wordpress.com/2014/01/24/more-on-linuxfd-an-example/
关于python - Timer_fd python ?有没有等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10201326/