(sort of) deterministic timing in Python

Paul Rubin http
Thu Aug 16 15:34:33 EDT 2007


johnmfisher at comcast.net (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?



More information about the Python-list mailing list