How to make thread sleep less than a millisecond on windows?
Answer / Kramank Rajput
In Windows, the smallest granularity for thread sleep is 15.625 microseconds. However, you can work around this limitation by using the `time.perf_counter()` function from Python's time module to achieve sub-millisecond accuracy.nHere's an example:n``pythonnimport timenimport threadingnndef sleep_less_than_ms(ms):n start = time.perf_counter()n elapsed = 0n while elapsed < ms:n if time.perf_counter() - start >= ms:n breakn elapsed += 1e-6n nif __name__ == '__main__':n threading.Thread(target=sleep_less_than_ms, args=(500,)).start()`
| Is This Answer Correct ? | 0 Yes | 0 No |
How do I open the run command?
Does windows 10 come with a spreadsheet program?
Is windows coming out with a new operating system?
Can I install windows 10 on android tablet?
How do I run chkdsk on c drive?
Why is my computer so slow all of a sudden windows 7?
Is it ok to disable sysmain?
Did windows 95 have ie?
How to bring a window to the front?
What is the minimum ram requirement for windows 10?
Is it safe to delete system queued windows error reporting?
How do I run a script in windows 10?