[python-win32] Win32 WaitableTimers and Python?

Jens B. Jorgensen jens.jorgensen at tallan.com
Thu Jul 17 15:02:50 EDT 2003


No a priori reason you could not use them but they do not seem to be in 
the win32event module wherein they'd likely be found if they were 
present. No need to let that stop you though. You could either write 
your own c(++) extension module or even better you could use the ctypes 
module. With ctypes if you wanted to wait 60 seconds you'd do this:

from ctypes import *
import win32event, win32api

h = windll.kernel32.CreateWaitableTimerA(None, 0, None)
dt = c_longlong(-60L * 10L**(9-2))
dt_p = pointer(dt)
windll.kernel32.SetWaitableTimer(h, dt_p, 0, None, None, 0)
win32event.WaitForSingleObject(h, win32event.INFINITE)
win32api.CloseHandle(h)

The ctypes home page is: http://starship.python.net/crew/theller/ctypes/

Graham Klyne wrote:

> Hi,
>
> I've been hunting through the book "Python Programming on Win32", 
> associated web pages, and Googling the web in general, without much 
> success, for an indication of whether CreateWaitableTimer and friends 
> can be used from Python; cf.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createwaitabletimer.asp 
>
>
> In particular, I'm looking to use timers to do periodic polling 
> functions in a service process.  I think I can use win32api.sleep for 
> now, but I don't like hogging a thread in this way.  Being a service 
> process, I think the window-based timers are inappropriate (if not 
> impossible) to use here.
>
> Any thoughts?
>
> (I'm not subscribed to this list, so please copy me on any comments.)
>
> Thanks.
>
> #g
>
>
> -------------------
> Graham Klyne
> <GK at NineByNine.org>
> PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32


-- 
Jens B. Jorgensen
jens.jorgensen at tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"  





More information about the Python-win32 mailing list