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


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

Re: subprocess.Popen instance hangs

Started byMRAB <python@mrabarnett.plus.com>
First post2013-08-29 20:01 +0100
Last post2013-08-29 20:01 +0100
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 MRAB <python@mrabarnett.plus.com> - 2013-08-29 20:01 +0100

#53251 — Re: subprocess.Popen instance hangs

FromMRAB <python@mrabarnett.plus.com>
Date2013-08-29 20:01 +0100
SubjectRe: subprocess.Popen instance hangs
Message-ID<mailman.368.1377802908.19984.python-list@python.org>
On 29/08/2013 19:34, Tim Johnson wrote:
> using Python 2.7.1 on OS X 10.7.5
>
> I'm managing a process of drush using an instance of subprocess.Popen
>
> The process has a '--verbose' option. When that option is passed as
> part of the initializer `args' argument, the process will hang.
>
> It should be no surprise as drush output with the --verbose option
> can be _extremely_ verbose, and I can do without it, but I would
> like to learn how to handle it. I've googled this topic, but my poor
> little brain is yet to sort out all of the content found.
>
> ## my relevant code follows :
> p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
> ## wait() is 'forever' if '--verbose' used
> exit_status = p.wait()
> output = p.stdout.read()
> ## done
>
> I 'suspect' that using a tempfile may be the solution, if so, I
> 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.

[toc] | [standalone]


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


csiph-web