How do I run routines where timing is critical?

Terry Reedy tjreedy at udel.edu
Thu Jun 24 00:15:57 EDT 2004


"S. David Rose" <photos at conversent.net> wrote in message
news:GorBc.75458$V57.10872803 at news4.srv.hcvlny.cv.net...
>   I want a main loop which takes photos from 8 different web-cams, each
can
> be addressed by http://ip-addr/image.jpg.

Public web cams generally update once every few seconds, or slower, so I
presume these are private cameras on a private net.

>  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.

Your proto-code below shows the 'remaining 2' being polled 4 times a
second.

How long does it take to 'poll' a camera and process the data and be ready
for another?  IOW,

>  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.

(Stackless tasklets might also be a possibility, but I have 0 experience
therewith).
Once a second will not get you several times a second.  Unless cameras
respond 'immediately', you may need to make several requests and process
replies as they come.

> 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.
>
> In otherwords,
>
> While 1
>   if second >1.00 and <1.25
>      Camera 1 & camera 2
>      Camera 5 & camera 6 & camera 7 & camera 8
>
>   if second >1.25 and < 1.50
>      Camera 1 & camera 2
>
>   if second >1.50 and <1.75
>      Camera 1 & camera 2
>      Camera 5 & camera 6 & camera 7 & camera 8
>
>   if second >1.75 and < 2.0
>      Camera 1 & camera 2
>
>   if second >1.00 and < 1.334
>      Camera 3 & camera 4
>
>   if second > 1.334 and < 1.667
>      Camera 3 & camera 4
>
>   if second > 1.667 and < 2.000
>      Camera 3 & camera 4

How critical is the timing?  Above suggests some sloppiness is allowed.  If
so, following schedule might work (where '3A' is first 3-time-a-second
camera, etc).

0.00 3A,3B
       pause
0.25 2A,2B,2C,2D
0.33 3A,3B
       pause
0.50 1A,1B
       pause
0.66 3A,3B
0.75 2A,2B,2C,2D
       pause
and repeat

pause periods could be used to process previously collected data.

Terry J. Reedy







More information about the Python-list mailing list