Trying to chain processes together on a pipeline

Chris Rebert clp2 at rebertia.com
Fri Jul 1 04:24:50 EDT 2011


On Fri, Jul 1, 2011 at 1:02 AM, Andrew Berg <bahamutzero8825 at gmail.com> wrote:
> On 2011.07.01 02:26 AM, Peter Otten wrote:
>> I can't reproduce your setup, but I'd try using communicate() instead of
>> wait() and close().
> I don't really know what communicate() does.

"Read data from stdout and stderr, until end-of-file is reached. Wait
for process to terminate."
It then returns the read data as two strings. It's pretty straightforward.

> The docs don't give much
> info or any examples (that explain communicate() anyway), and don't say
> when communicate() is useful.

They are slightly roundabout in that respect. The warnings for .wait()
and .stdout/err explain communicate()'s utility:
"Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE
and the child process generates enough output to a pipe such that it
blocks waiting for the OS pipe buffer to accept more data. ***Use
communicate() to avoid that.***" [emphasis added]

Cheers,
Chris
--
http://rebertia.com



More information about the Python-list mailing list