How do I run routines where timing is critical?

Paul Rubin http
Mon Jun 21 04:46:21 CEST 2004

"S. David Rose" <photos at> writes:
>   I want a main loop which takes photos from 8 different web-cams,
> each can be addressed by http://ip-addr/image.jpg.  That's the easy
> part, but I want to have 2 cameras poll 3-times a second, 4 cameras
> poll 2 times a second, and the remaining 2 cameras poll once a
> second.  I have found lots of info suggesting the use of threads for
> this, all using sleep to have a single event fire every second or
> so.  But, what I'd like to do is have a loop which does not need to
> 'sleep' but can rather evaluate where I am in the second and then
> have that logic trigger the event.

You have to do some pretty advanced stuff if you want to make sure of
accurate timing.  But if you just want to sleep for 1/4 of a second and
can tolerate some slop, you can say

  import time

I.e. you don't have to sleep an integer number of seconds.

More information about the Python-list mailing list