[python-win32] sleep() for less than .001s?
Ray Schumacher
rays at blue-cove.com
Fri Aug 4 19:58:55 CEST 2006
At 10:29 AM 8/4/2006, Tim Roberts wrote:
>Ray Schumacher wrote:
>
>> I have been trying to use sleep() and kernel32.QueryPerformanceCounter
>> together; I want to delay until a particular tick without trying up
>> the CPU badly.
>> However, while time.sleep(.001) relieves the CPU, it has wildly
>> unpredictable delay, and sleep(.0001) delays almost nothing at all!
>> (I'm watching the parallel port on a scope).
>> If I use a while and just count ticks with QueryPerformanceCounter(),
>> it is very stable and as desired - but it uses 100% CPU.
>>
>> RTAI LINUX has a nanosleep() function that does it all very nicely on
>> our Debian install, is there a parallel in Win32?
>> The MS Sleep() function is in integer milliseconds...
>
>
>No. Windows simply has no mechanism for doing sub-millisecond sleeps.
>The default scheduling interval in XP is 10 milliseconds. You can't get
>an interrupt more granular than that, even in kernel mode.
ahh
>It is
>possible to change the scheduling interval to 1 millisecond by using
>timeBeginTime, although performance suffers.
I see a timeBeginPeriod (?):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp
used with timeGetTime, normally...
"Windows NT/2000: The default precision of the timeGetTime function can be five milliseconds or more, depending on the machine. You can use the <http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_timebeginperiod.asp>timeBeginPeriod and <http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_timeendperiod.asp>timeEndPeriod functions to increase the precision of timeGetTime. If you do so, the minimum difference between successive values returned by timeGetTime can be as large as the minimum period value set using timeBeginPeriod and timeEndPeriod. Use the QueryPerformanceCounter and QueryPerformanceFrequency functions to measure short time intervals at a high resolution,
Windows 95: The default precision of the timeGetTime function is 1 millisecond. In other words, the timeGetTime function can return successive values that differ by just 1 millisecond. This is true no matter what calls have been made to the timeBeginPeriod and timeEndPeriod functions. "
I'll fiddle with these later.
>It is possible to use QueryPerformanceCounter to do a spin-stall, but
>you are essentially in an infinite loop. ALSO remember that you are
>still sharing the CPU with other processes. If another process decides
>it wants to hog the CPU for its whole time slice, you'll lose 10
>milliseconds. If a driver decides it needs to do a thermal
>recalibration on your disk drive and stalls for 5 milliseconds, you'll
>lose 5 milliseconds.
>
>Remember that RTAI LINUX is a real-time operating system designed for
>deterministic processing. Windows most definitely is not.
Thanks for the info,
Ray
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060804/9f0125c1/attachment.htm
More information about the Python-win32
mailing list