Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34127
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: pyHook and time libraries |
| Date | 2012-12-01 14:26 -0500 |
| Organization | > Bestiaria Support Staff < |
| References | <9cc06bdd-8254-4f6b-9ce3-0a43b229ca14@googlegroups.com> <mailman.391.1354304894.29569.python-list@python.org> <c30a77db-6254-49c2-acab-897def23599e@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.404.1354389995.29569.python-list@python.org> (permalink) |
On Sat, 1 Dec 2012 05:38:39 -0800 (PST), doronmmm@gmail.com declaimed
the following in gmane.comp.python.general:
<stripping practically everything>
> def sendEmailAuto(dt,openfile):
> tt = time.time()
> nn = tt+dt
>
> while tt<nn:
Ugh... A CPU intensive polling loop!
The simplest way to delay is to use time.sleep()
while True:
time.sleep(300.0) #5min * 60sec
There is no guarantee that this will fire exactly 5min later -- but
should fire as soon after 5min as it gets control...
> def OnMouseEvent(event):
> global log
Why bother defining "log" as global, when the only contents used are
local messages being written to a file?
>
> thread.start_new_thread(sendEmailAuto, (10,openfile))
>
> hm = pyHook.HookManager()
> hm.KeyDown = OnKeyboardEvent
> hm2 = pyHook.HookManager()
> hm2.MouseAll = OnMouseEvent
>
> hm.HookKeyboard()
> hm2.HookMouse()
>
> pythoncom.PumpMessages()
>
Uhm... I don't know if pythoncom (or the PumpMessages() ) method is
Python friendly -- that is, if it DOESN'T release the GIL at some point,
your email thread will never get control. Compare the difference between
.PumpMessages() and .PumpWaitingMessages(). The latter only runs the
currently pending batch and returns (which will definitely allow your
thread to run) -- the implication is the .PumpMessages() won't return
until the (implied) window is closed. Using .PumpWaitingMessages() will
require making a loop in the main thread...
while True:
if pythoncom.PumpWaitingMessages(): break #window closed
time.sleep(0.0) #ensure threading task swapping can happen
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
pyHook and time libraries Doron <dorimeshi@gmail.com> - 2012-11-29 22:03 -0800
RE: pyHook and time libraries "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-30 19:47 +0000
Re: pyHook and time libraries doronmmm@gmail.com - 2012-12-01 05:38 -0800
Re: pyHook and time libraries Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-01 14:26 -0500
Re: pyHook and time libraries doronmmm@gmail.com - 2012-12-01 05:38 -0800
csiph-web