OK, to be more specific, I would like to run the code, when the value
of seconds in the timestamp become say "00".
The whole code will run in the infinitive loop and other actions will
be executed as well, so it can not "sleep" for 60 seconds
.
Simplest solution would be to put the timed portion into a separate
thread, with a long enough sleep call to minimize task switching
overhead. However, even in a thread, you can not enforce that a sleep
will end on any given portion of the time -- if the other code calls a
poorly written C-extension that doesn't give up the global interpreter
lock until it is complete (say it runs 40 seconds and your sleep on set
for 10 seconds -- that sleep may not return for up to 50 seconds
[9.99999 seconds of sleep, and then the 40 second extension started]).
No matter what you put in for the sleep value, that only specifies a
/minimum/ period.
Within this thread, something like the following will set the
sleep...
.... t0 = time.time()
.... t1 = 60.0 + (t0 - (t0 % 60.0))
.... time.sleep(t1 - t0)
.... now = time.time()
.... print t1, t0, t1 - t0, now
.... print time.ctime(t1), time.ctime(t0), time.ctime(now)
.... 1147195680.0 1147195627.13 52.875 1147195680.0
Tue May 09 10:28:00 2006 Tue May 09 10:27:07 2006 Tue May 09 10:28:00
20061147195740.0 1147195688.52 51.4839999676 1147195740.0
Tue May 09 10:29:00 2006 Tue May 09 10:28:08 2006 Tue May 09 10:29:00
2006
.... to wake up on the next minute. Notice how my keyboard entries
resulted in sleeps of ~52 seconds. This scheme adjusts for the
processing performed during each activation, and the inherent
uncertainty in wake up time.
The only other means would be something of a discrete event
dispatcher, where ALL of your code is written to do maybe one or two
statements at a time and return, and the main program just increments
time and calls each operation that is supposed to run on that time
step... Lot's of overhead, difficult to code number crunchers to return
in mid-computation... etc.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/