Python Forum
How to achieve close to 1ms time.sleep - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to achieve close to 1ms time.sleep (/thread-17019.html)



How to achieve close to 1ms time.sleep - kwekey - Mar-25-2019

Hi, I have a program that runs on both windows and Linux as a continuous thread with 1 millisecond interval, using time.sleep(0.001)

My programs seem to run slow on Windows than in Linux. After some finds, I noticed this:

"The time.sleep() function uses the underlying operating system's sleep() function. Ultimately there are limitations of this function. For example on a standard Windows installation, the smallest interval you may sleep is 10 - 13 milliseconds. The Linux kernels tend to have a higher tick rate, where the intervals are generally closer to 1 millisecond"

Is there any way to achieve the close to 1 milliseconds on Windows?

Please help me..

Thanks
kwekey


RE: How to achieve close to 1ms time.sleep - Larz60+ - Mar-25-2019

exact timing is almost impossible without an event driven timer/counter especially on windows. That said,
this may be of interest: https://stackoverflow.com/a/11658115