[python-win32] sleep() for less than .001s?

Ray Schumacher rays at blue-cove.com
Fri Aug 4 03:45:00 CEST 2006


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

sample code:
___________________________________________________________________

TTLHighDur = ticksPerMs/2
currTicksPerRot = fsTicksPerRot
qPC(byref(c0))
tick0 = c0.value # initial count
nextTTL = tick0
## make a TTLOUT 
endTick = tick0+pF* 15 #seconds
rotN = 0

while(True):
    nextTTL = currTicksPerRot+nextTTL
    sleep(.0001)# sleep for most of the time needed
    while(True): #loop until the exact tick
        qPC(byref(c1))
        if c1.value>nextTTL: break
    out(0x378, 0xFF) #set all bits high
    while(True): #loop until the exact tick
        qPC(byref(c1))
        if c1.value>nextTTL+TTLHighDur: break
    out(0x378, 0x00) #set all bits low
    rotN += 1
    
    if c1.value>endTick: break



Ray Schumacher
Blue Cove Interactive
8580 Production Avenue, Suite B
San Diego, CA 92121
858.695.8801
http://Blue-Cove.com


Disclaimer ;-)
By sending an email to ANY of my addresses you are agreeing that: 
    * I am by definition, "the intended recipient" 
    * All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. In particular, I may quote it on USENET. 
    * I may take the contents as representing the views of your company. 
    * This overrides any disclaimer or statement of confidentiality that may be included on your message. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060803/e7d10945/attachment-0001.html 


More information about the Python-win32 mailing list