开发者

threading.Timer time precision

What does the time accuracy of Python's threading.Timer depend on?

Does it depend on the OS used?

Does it depend on the Python implementation开发者_开发技巧 used?

Does it depend on the interval?

How can it be benchmarked?

Are there already benchmarks out there?


In CPython, the threading.Timer accuracy (waiting part) is based on a Condition.wait() call.

The Condition.wait() (implemented here) is done by successive sleep with a delay of min(delay * 2, remaining, .05) where delay is originally set at 0.0005 # 500 us -> initial delay of 1 ms. According to this implementation (that is OS independant) we can argue that the accuracy is at least the time.sleep accuracy.

But, the time.sleep() accuracy is based on the OS used (here is the implementation : floatsleep()), on Windows, it uses the WaitForSingleObject() with a internal windows timer, on Linux it uses the select() method.

At least, because apart the sleep delay, the charge of the OS could interfer with the reactivity of the python process, the scheduling algorithm can also have an influence on the accuracy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜