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


Groups > comp.lang.python > #53298

Re: subprocess.Popen instance hangs

From Nobody <nobody@nowhere.com>
Subject Re: subprocess.Popen instance hangs
Date 2013-08-30 15:47 +0100
Message-Id <pan.2013.08.30.14.47.27.111000@nowhere.com>
Newsgroups comp.lang.python
References <20130829183418.GE414@mail.akwebsoft.com> <mailman.377.1377824422.19984.python-list@python.org>
Organization Zen Internet

Show all headers | View raw


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).

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


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