On 8/17/07, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > > "Paul Rubin" <http://p..id> wrote: > > > >[EMAIL PROTECTED] (John Fisher) writes: > >> mark start time > >> start event > >> event finishes > >> count time until next interval > >> start second event… > >> > >> rather than this: > >> > >> start event > >> event finishes > >> sleep for interval > >> start second event > >> ... > >> So how do I accomplish this in Python with a minimum of labour? > > > >Normally I'd use something like: > > > > from time import time > > > > t0 = time() > > start event ... event finishes > > t1 = time() > > elapsed = t1 - t0 > > sleep(interval - elapsed) > > start second event ... > > > >Am I missing something? > > Not much - only beware of cases when elapsed is greater than > interval - not sure what time.sleep(negative_number) does. >
On Windows 2k3, Python 2.5 it sleeps forever (or almost forever? Maybe a signed/unsigned thing) so yeah, be careful of it. -- http://mail.python.org/mailman/listinfo/python-list