[python-win32] Re: sleep() fine-control in Python - RDTSC,
select() etc.
RayS
rays at blue-cove.com
Tue Jan 25 06:23:30 CET 2005
At 11:48 PM 1/24/2005 -0300, Gabriel Genellina wrote:
>At 24/1/2005 21:24, you wrote:
>
>>I have a need for a time.clock() with >0.000016 second (16us) accuracy.
>>The sleep() (on Python 2.3, Win32, at least) has a .001s limit. Is it lower/better on other's platforms?
>
>Try a waitable timer <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitable_timer_objects.asp>
>SetWaitableTimer specifies the interval with 100ns granularity, but maybe the actual timer precision depends on hardware or OS version or ...
Thanks!
Upon searching I found:
http://mail.python.org/pipermail/python-win32/2003-July/001166.html
from ctypes import *
import win32event, win32api
h = windll.kernel32.CreateWaitableTimerA(None, 0, None)
#dt = c_longlong(-60L * 10L**(9-2)) ## 60s * 1/(100nanoseconds)
dt = c_longlong(-160L) ## 16microseconds
dt_p = pointer(dt) ## uses 100ns increments
windll.kernel32.SetWaitableTimer(h, dt_p, 0, None, None, 0)
win32event.WaitForSingleObject(h, win32event.INFINITE)
win32api.CloseHandle(h)
I expect the actual timing to be off, but I'll be switching methods and/or hardware after this first demo app to a real-time OS or an A/D with counters.
I'll post benched code tomorrow.
Ray
More information about the Python-win32
mailing list