【问题标题】:Timer_fd python ? is there an equivalentTimer_fd 蟒蛇?有没有等价物
【发布时间】:2012-04-18 00:56:34
【问题描述】:

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

【问题讨论】:

  • 你希望通过“设置计时器”来完成什么?也许你的问题可以在更高的层次上得到解决。
  • 我想每 5 秒从文件中读取一个值。

标签: python linux asynchronous epoll


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多