Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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; 'win32': 0.03; 'url:msdn': 0.07; 'api': 0.09; 'newest': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'windows,': 0.09; 'thread': 0.11; 'times,': 0.13; 'count.': 0.16; 'increment': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'replaces': 0.16; 'stream.': 0.16; 'subject:GUI': 0.16; 'subject:image': 0.16; 'there?': 0.16; 'thread-safe': 0.16; 'threaded': 0.16; 'true:': 0.16; 'url:85)': 0.16; 'windows': 0.19; 'feb': 0.19; 'changes': 0.20; 'sort': 0.21; 'trying': 0.21; 'do.': 0.21; '(on': 0.22; 'absolute': 0.23; 'changes,': 0.23; 'seems': 0.23; 'command': 0.24; 'handling': 0.27; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; 'chase': 0.29; 'closer': 0.29; 'leaves': 0.29; 'manual': 0.29; 'class': 0.29; 'fri,': 0.30; 'figure': 0.30; 'code': 0.31; 'file': 0.32; 'etc.)': 0.32; 'could': 0.32; 'directory,': 0.33; 'url:home': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; "can't": 0.34; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'created': 0.36; 'but': 0.36; 'url:library': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'available.': 0.37; 'reported': 0.37; 'level': 0.37; 'two': 0.37; 'being': 0.37; 'passed': 0.37; 'previous': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'behind': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'url:microsoft': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'url:aspx': 0.60; 'most': 0.61; 'matter': 0.61; 'monitoring': 0.61; 'latest': 0.61; 'series': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'url:en-us': 0.65; 'url:%1': 0.68; 'believe': 0.69; 'race': 0.71; 'completion': 0.78; '2013': 0.84; 'conclude': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Monitoring updating directory for image for GUI Date: Fri, 08 Feb 2013 20:32:29 -0500 Organization: > Bestiaria Support Staff < References: <8a572770-9cc1-4b65-9053-10fd6c2f543b@googlegroups.com> <02bee1ed-1a9b-4cac-975a-098b3382250f@googlegroups.com> <8f8eaf8f-2572-4843-87f0-3bafaf98472b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-253-106-181.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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360373560 news.xs4all.nl 6879 [2001:888:2000:d::a6]:37578 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38489 On Fri, 8 Feb 2013 09:09:31 -0800 (PST), ciscorucinski@gmail.com declaimed the following in gmane.comp.python.general: > > That is what I am trying to figure out how to do. I have a counter that updates with every note that is grabbed from the stream. That counter is passed into a threaded class that might or might not create the image right away...but seems to create them sequentially from what I have seen so far (I don't know if that is absolute thought). > > Please let me know you thought on the above part! Each new thread should only take only a very small amount longer to do than the previous thread that was started...because it has one more note to deal with this time. > > Anyways...I do have the count of the latest image that WILL BE created...but by the time that one is created in the directory, a new note is most likely streamed in and replaces that count. Therefore, I cannot really do that...I think. > > hmmmm, I wonder. I create the images via OS command that will .wait() on a subprocess.Popen(). I could increment the counter there? Or do something there that will let me know of the most recent image file via a counter or something? But it needs to be thread-safe > One problem I see is a race condition. Unless you have some sort of completion flag from the program generating the images you can't rely on the "newest" file in the directory being a complete image. So... You either run one image behind if just looking at directory contents (on the basis the newest image file is still being written); or you have to run lock-step with the image generator, where it signals when is available. If monitoring a directory for changes, and you are on Windows, I believe there is a native Win32 API to catch changes to directories. {I'm still waiting for Windows Internals Part 2 to arrive -- though this series is closer to the old VMS "black book" than to a reference manual for Windows system calls} http://msdn.microsoft.com/en-us/library/windows/desktop/aa365261%28v=vs.85%29.aspx You still have the chase condition unless you code a two level change... displayFile = None inWorkFile = None while True: #wait for change notification of new file (ignore times, etc.) displayFile = inWorkFile inWorkFile = #whatever the change notification reported if displayFile: #do something with completed file ... and that leaves the matter of handling the last file when you conclude there will be no more updates. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/