Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34127

Re: pyHook and time libraries

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python': 0.09; '"log"': 0.09; 'closed.': 0.09; 'global,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'thread': 0.11; 'dec': 0.15; 'sat,': 0.15; 'polling': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'threading': 0.16; 'time.time()': 0.16; 'true:': 0.16; 'later': 0.16; '(or': 0.18; 'skip:p 30': 0.20; 'pending': 0.20; 'written': 0.20; 'latter': 0.22; 'runs': 0.22; 'task': 0.23; '(which': 0.26; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'cpu': 0.29; 'gil': 0.29; 'window': 0.30; 'gets': 0.32; 'defining': 0.33; 'point,': 0.33; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'skip:. 20': 0.35; "won't": 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'compare': 0.36; 'method': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'being': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'release': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'fire': 0.62; 'between': 0.63; 'email addr:gmail.com': 0.63; 'making': 0.64; 'soon': 0.70; 'friendly': 0.71; 'dennis': 0.91; 'received:108': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: pyHook and time libraries
Date Sat, 01 Dec 2012 14:26:36 -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>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-68-176-8.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 3.3/32.846
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.404.1354389995.29569.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354389995 news.xs4all.nl 6971 [2001:888:2000:d::a6]:45696
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34127

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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