Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53264
| Date | 2013-08-29 14:56 -0800 |
|---|---|
| From | Tim Johnson <tim@akwebsoft.com> |
| Subject | Re: subprocess.Popen instance hangs |
| References | <20130829183418.GE414@mail.akwebsoft.com> <521F9AA4.1050406@mrabarnett.plus.com> |
| Organization | AkWebsoft |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.376.1377816994.19984.python-list@python.org> (permalink) |
* 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
Re: subprocess.Popen instance hangs Tim Johnson <tim@akwebsoft.com> - 2013-08-29 14:56 -0800
csiph-web