Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53301
| Date | 2013-08-30 07:32 -0800 |
|---|---|
| From | Tim Johnson <tim@akwebsoft.com> |
| Subject | Re: subprocess.Popen instance hangs |
| References | <20130829183418.GE414@mail.akwebsoft.com> <mailman.377.1377824422.19984.python-list@python.org> <pan.2013.08.30.14.47.27.111000@nowhere.com> |
| Organization | AkWebsoft |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.390.1377876752.19984.python-list@python.org> (permalink) |
* Nobody <nobody@nowhere.com> [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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: subprocess.Popen instance hangs Tim Johnson <tim@akwebsoft.com> - 2013-08-29 17:00 -0800
Re: subprocess.Popen instance hangs Nobody <nobody@nowhere.com> - 2013-08-30 15:47 +0100
Re: subprocess.Popen instance hangs Tim Johnson <tim@akwebsoft.com> - 2013-08-30 07:32 -0800
Re: subprocess.Popen instance hangs Jerry Hill <malaclypse2@gmail.com> - 2013-08-30 11:38 -0400
Re: subprocess.Popen instance hangs Tim Johnson <tim@akwebsoft.com> - 2013-08-30 10:43 -0800
csiph-web