for loops longer on a P-IV???

Peter Hansen peter at
Thu Aug 1 06:15:05 CEST 2002

Chris wrote:
> This is our wait function:
> def wait(Seconds):
>         loop = Seconds * 50
>         for i in range (0,loop):
>                 win32api.Sleep(20)
>                 if win32ui.PumpWaitingMessages(0,-1):
>                         win32api.PostQuitMessage()
>                         raise exceptions.SystemExit
> A 10 second wait on our P-IV seems to take 15 seconds [....]

I'm not certain what you are actually expecting, but the code you
have here is effectively the following for a "10 second" delay:

 do this 500 times:
    wait at least 20 milliseconds
    do some other stuff that takes an undefined amount of time

It looks like you think this should take 500*20 milliseconds
to complete, but there are at least two sources of additional
delay -- the "at least" part, and the "other stuff" part.  
You are actually accumulating error and the finer the period of 
the sleep, the more inaccurate the overall time will be.

If you're looking for accuracy in timing, this is not the way
to go about it.


More information about the Python-list mailing list