time module precision

janeaustine50 at hotmail.com janeaustine50 at hotmail.com
Sun Jan 9 12:09:27 CET 2005

Tim Peters wrote:
> Python's time.sleep() calls the Win32 API Sleep() function on
>  All behavior is inherited from the latter.  See MS's docs:

Oh, after a short research, I found that time.sleep uses its customized
way of sleeping using "select".


So I think its behaviour is more complicated than single MS Sleep call,
I suppose.

> In particular, MS Sleep() takes an integer argument, giving the
> of milliseconds to sleep.  Your 0.0001 case falls under the special
> Sleep(0) case due to truncation in float->int conversion.

Oh, I see.

> Also Google on
>     sleep thread deviation
> to find an interesting CodeProject article quantifying behavior on
> particular tester's Windows box.  Also see an article it references
> for approaches to the question "how do I handle small intervals?"
> (short course:  you probably can't, unless we're willing to throw
> money at it).

Thanks for the references.

What I want to do is waiting(not busy-delaying) for a few tens to
hundreds of microseconds in some threads. The closet solution I got is
using windows QueryPerformanceCounter (in Python, time.clock) with busy
looping checking if we have past the target time. However, that makes
the cpu usage upto almost 100%.

So the problem (waiting tens to hundreds of us without busy looping)
still remains...

More information about the Python-list mailing list