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


Groups > comp.lang.python > #53264

Re: subprocess.Popen instance hangs

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tim@akwebsoft.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'mrab': 0.05; 'output': 0.05; 'method.': 0.07; 'subject:skip:s 10': 0.07; 'exit': 0.09; 'output,': 0.09; 'subject:instance': 0.09; 'terminated': 0.09; "%s'": 0.16; "(you're": 0.16; 'argument.': 0.16; 'blocks': 0.16; 'fine.': 0.16; 'forty': 0.16; 'stdout': 0.16; 'wrote:': 0.18; 'finished': 0.19; 'header:User-Agent:1': 0.23; 'error': 0.23; 'handling': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'errors': 0.30; 'code': 0.31; 'comments': 0.31; 'skip:s 70': 0.31; 'terminate': 0.31; 'file': 0.32; 'figure': 0.32; 'quite': 0.32; 'open': 0.33; "can't": 0.35; 'johnson': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'process,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'break': 0.61; "you're": 0.61; 'content-disposition:inline': 0.62; 'here': 0.66; 'status:': 0.68; 'examples.': 0.84; 'replies.': 0.84
Date Thu, 29 Aug 2013 14:56:21 -0800
From Tim Johnson <tim@akwebsoft.com>
To python-list@python.org
Subject Re: subprocess.Popen instance hangs
Mail-Followup-To python-list@python.org
References <20130829183418.GE414@mail.akwebsoft.com> <521F9AA4.1050406@mrabarnett.plus.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <521F9AA4.1050406@mrabarnett.plus.com>
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 <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.376.1377816994.19984.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377816994 news.xs4all.nl 15875 [2001:888:2000:d::a6]:34324
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53264

Show key headers only | View raw


* MRAB <python@mrabarnett.plus.com> [130829 11:04]:
> On 29/08/2013 19:34, Tim Johnson wrote:
> >could use some examples.
> >
> The subprocess will terminate when it has finished writing its output,
> but because you're not consuming any of the output (you're waiting for
> it to finish), the buffer fills up and blocks the subprocess.
> 
> Try reading the output or using the .communicate method.
> 
> Alternatively, pass an open file as the stdout argument.
> 
  Kudos to all for the replies. Here is some code to review:
## execute process and read output  
p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
while 1 :
    output = p.stdout.read()
    if output :
        print(output)
    else : break

## Check for errors  
exit_status = p.wait()
if exit_status :
    if p.stderr :
        self.__err('Process terminated with exit status: %s' % (str(exit_status)),
                   'Following error message was found:'
                    p.stderr.read())
    else :
        self.__err('Process terminated with exit status: %s' % (str(exit_status)))

Without any error from the drush process, this works fine.

I can't quite figure out how to simulate/cause an error from drush,
so I would welcome comments on the error handling

thanks again
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: subprocess.Popen instance hangs Tim Johnson <tim@akwebsoft.com> - 2013-08-29 14:56 -0800

csiph-web