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


Groups > comp.lang.python > #53264 > unrolled thread

Re: subprocess.Popen instance hangs

Started byTim Johnson <tim@akwebsoft.com>
First post2013-08-29 14:56 -0800
Last post2013-08-29 14:56 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#53264 — Re: subprocess.Popen instance hangs

FromTim Johnson <tim@akwebsoft.com>
Date2013-08-29 14:56 -0800
SubjectRe: subprocess.Popen instance hangs
Message-ID<mailman.376.1377816994.19984.python-list@python.org>
* 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web