Python Forum

Full Version: Is there a difference between Python’s time.sleep and win32api.Sleep?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know that win32api.Sleep is related to the windows API, and it is obvious that Python's default time.sleep param is in seconds, and win32api.Sleep is in milliseconds, other than that is there a difference between time.sleep, and win32api.Sleep? I like the idea that win32api.Sleep is in milliseconds and I'm considering using it over time.sleep.
win32api would appear to be windows only. python's time sleep will work on all os.
(Sep-20-2024, 11:36 AM)menator01 Wrote: [ -> ]win32api would appear to be windows only. python's time sleep will work on all os.
This I know. win32api is part of the PyWin32 package which is a wrapper for the Windows API.
(Sep-20-2024, 09:43 AM)phpjunkie Wrote: [ -> ]I like the idea that win32api.Sleep is in milliseconds and I'm considering using it over time.sleep.
Just because time.sleep() takes seconds (which may have a fractional part), doesn't mean it is less precise or accurate.

The documentation for time.sleep says that on Windows, it uses a High-Resolution timer with a resolution of 100 nanoseconds.
The obvious difference is that win32api. Sleep is not portable while time. sleep is. If you're certain that your program will never need to run on a non-windows system this doesn't matter, but it's generally a good idea to try to write as portable code as possible.