使用 python:以 x:00 重复的间隔
如何安排 5 分钟间隔的重复计时器。在 00 秒触发,然后在 00 秒重复。好吧,不是硬实时,但尽可能接近系统滞后。试图避免滞后累积并接近 00。Lang
:Python,操作系统:WinXP x64
系统具有 25 毫秒分辨率。
任何代码都会有帮助,蒂亚
How do I sched a repeat timer for 5 min intervals. Which fire at 00 seconds, then repeat at 00. Ok, not hard real-time but as close as possible with sys lags. Trying to avoid a build up in lags and get near 00.
Lang: Python, OS: WinXP x64
System has 25ms resolution.
Any code would be helpful, tia
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何比 threading.Timer< 更准确地做到这一点/a>.它是“一次性”的,但这只是意味着您以这种方式安排的功能必须立即重新安排自己 300 秒后,第一件事。 (您可以通过每次使用
time.time
测量准确时间并相应地改变下一个调度延迟来提高准确性)。I don't know how to do it any more accurately than with threading.Timer. It's "one-shot", but that just means the function you schedule that way must immediately re-schedule itself for another 300 seconds later, first thing. (You can add accuracy by measuring the exact time with
time.time
each time and varying the next scheduling delay accordingly).尝试比较这两个代码示例的时间打印输出:
代码示例 1
代码示例 2
Try and compare the time printouts of these two code samples:
Code Sample 1
Code Sample 2