1

我想知道如何使用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
4

1 回答 1

2

此答案仅适用于 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/

于 2017-12-04T04:29:23.853 回答