python - Timer_fd python ?有没有等价物

标签 python linux asynchronous epoll

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

相关文章:

javascript - 异步数据加载后提交 HTML 表单的正确方法是什么?

javascript - 跨浏览器 javascript 加载回调 : Is there a better way than using iframes?

python - 在 Python 中组合模块文件

python - 为什么使用 PIL 调整 JPEG 图像的大小会增加文件大小?

python - 减少数据噪音

c - 从用户空间访问注册物理地址

linux - 哪种双栈服务器方法更好?

python - 为什么 Nodejs 可以做文件 I/O 异步而 Python asyncio 不能?

python - pandas - 读取文件之前/之后不同的数据类型列

linux - 适用于 Linux 的 Docker 和 Kubernetes 存储库