[Tutor] Accuracy of time.sleep()
alan.gauld at freenet.co.uk
Sun Dec 5 00:44:09 CET 2004
> (and yes, there are some versions of cron for Windows -- I don't
> where they can be found, but I used one called nnCron Lite at my job
> this summer)
And on XP/Win2K you can use the 'at' command to schedule jobs.
The only case for sleep() is if you need to maintain context in
memory (maybe because some other interrupt can come in too).
Even then sleep is not, as you discovered absolutely accurate, it
depends on things like CPU load. Instead I'd set sleep to wake me
up a few minutes early (10 minutes say?), then run a new fuction
to calculate the time to go and sleep for the shorter period, then
for the last few seconds sleep for a few seconds at a time and
check time each wake up. Of course even that only gets you within
a second or two.
Other options are to use the system clock and interrupts or signals.
But if possible go with cron or at - thats why thety are there!
Author of the Learn to Program web tutor
More information about the Tutor