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: 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 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> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, 1 Dec 2012 05:38:39 -0800 (PST), doronmmm@gmail.com declaimed the following in gmane.comp.python.general: > def sendEmailAuto(dt,openfile): > tt = time.time() > nn = tt+dt > > while tt 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/