time module precision

janeaustine50 at hotmail.com janeaustine50 at hotmail.com
Sun Jan 9 06:09:27 EST 2005


Tim Peters wrote:
[snip]
> Python's time.sleep() calls the Win32 API Sleep() function on
Windows.
>  All behavior is inherited from the latter.  See MS's docs:
>
>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sleep.asp>

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

http://groups.google.com/groups?threadm=ud7i1c9ck.fsf%40ctwd0143.fitlinxx.com

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
number
> 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
one
> 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