[Tutor] Accuracy of time.sleep()

Dave S pythontut at pusspaws.net
Mon Dec 6 00:08:34 CET 2004


Jacob S. wrote:

>You know, since time.sleep() builds up errors, this is what I do to keep it
>purely pythonic... (not tested)
>
>from time import gmtime
>
>alarmhr = 8
>alarmmin = 5
>alarmsec = 0
>
>while 1:
>    t = gmtime()
>    hour = t[3]
>    min = t[4]
>    sec = t[5]
>    if (alarmhr,alarmmin,alarmsec) == (hour,min,sec):
>        print "It is 8:05 AM. Please do whatever you are supposed to at this
>time.
>        raw_input()
>        break
>
>  
>
Yep this is an option that makes sense to me, getting time once & 
breaking it down with []'s to avoid the trap I almost fell into. I know 
cron is probarbly the way to go but .... Its kind of nice to keep it all 
Python if you know what I mean ;-)

Dave



More information about the Tutor mailing list