简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM