Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'subject:skip:s 10': 0.07; 'tries': 0.07; 'etc).': 0.09; 'merging': 0.09; 'output,': 0.09; 'subject:instance': 0.09; 'windows,': 0.09; 'works.': 0.09; 'def': 0.12; 'forty': 0.16; 'non-blocking': 0.16; 'stdout': 0.16; 'them...': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'appears': 0.22; 'aug': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'merge': 0.24; 'earlier': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'code': 0.31; '(on': 0.31; 'file': 0.32; 'skip:_ 10': 0.34; 'display': 0.35; 'something': 0.35; 'johnson': 0.35; 'but': 0.35; 'skip:s 60': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'thank': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'content-disposition:inline': 0.62; 'more': 0.64; 'worth': 0.66; 'nobody': 0.68; 'said:': 0.68; 'etc..': 0.84; 'streams': 0.84; '2013': 0.98 Date: Fri, 30 Aug 2013 07:32:29 -0800 From: Tim Johnson To: python-list@python.org Subject: Re: subprocess.Popen instance hangs Mail-Followup-To: python-list@python.org References: <20130829183418.GE414@mail.akwebsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Organization: AkWebsoft 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377876752 news.xs4all.nl 15997 [2001:888:2000:d::a6]:57457 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53301 * Nobody [130830 06:55]: > On Thu, 29 Aug 2013 17:00:21 -0800, Tim Johnson wrote: > > > ## This appears to be what works. > > def __exec(self,args) : > > """Run the process with arguments""" > > p = > > subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) > > while 1 : > > output = p.stdout.read() > > If the process tries to write more than a pipe's worth of data to stderr, > before closing stdout, it will block indefinitely. > > If you want to process both stdout and stderr, you have to be able to > consume the data in whatever order the process generates it, which means > either using multiple threads or (on Unix) select/poll or non-blocking > I/O. This is what the .communicate() method does (threads on Windows, > select/poll on Unix). > > The alternative is to merge both streams with stderr=subprocess.STDOUT, or > redirect one of them to a file (or /dev/null, etc). In earlier code I, I was merging them... :) Like I said: gnarly! What if I were to do something like: ## code while 1: output = p.stout.read() err = p.stderr.read() ## trapping for AttributeError, etc.. .... ## /code break'ing if either no output or value in `err' ?? The objective is to display all output, but to also separate error messages from normal output. thank you -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com