Python Forum

Full Version: How to achieve close to 1ms time.sleep
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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