How to make thread sleep less than a millisecond on windows?
Answer Posted / 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 |
Post New Answer View All Answers
What is the next version of windows after 10?
How much does a windows 10 license cost?
What does it cost to upgrade to windows 10?
What is the latest version of microsoft edge for windows 10?
How much does it cost for a copy of windows 10?
What is the next windows after 10?
How does registry work wedding?
How much does a copy of windows 10 cost?
What is the latest windows operating system?
When will the next windows os come out?
How do I add a google account to windows 10?
What is the current version of windows 10?