Re: subprocess.Popen does not close pipe in an error case

2010-01-10 Thread Nobody
On Wed, 06 Jan 2010 19:05:40 -0800, Steven K. Wong wrote: > Well, the example code at > http://www.python.org/ ... /subprocess.html#replacing-shell-pipeline > has the same issue: > Perhaps the doc can be improved to remind folks to close p1.stdout if > the calling process doesn't need it, unless

Re: subprocess.Popen does not close pipe in an error case

2010-01-09 Thread Nobody
On Wed, 06 Jan 2010 11:39:37 -0800, Steven K. Wong wrote: > Suppose now all the prog1.poll() calls/loop are replaced by a single > prog1.wait(). Without the explicit prog1.stdout.close(), prog1.wait() > will not return, so the calling process still hangs. Because calling > prog1.wait() means that

Re: subprocess.Popen does not close pipe in an error case

2010-01-06 Thread Steven K. Wong
Well, the example code at http://www.python.org/doc/2.6.2/library/subprocess.html#replacing-shell-pipeline has the same issue: output=`dmesg | grep hda` ==> p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) output = p2.communicate()[0] After communicate

Re: subprocess.Popen does not close pipe in an error case

2010-01-06 Thread Steven K. Wong
On Jan 6, 10:30 am, Nobody wrote: > I think that you should close prog1.stdout here. Otherwise, there will > be two readers on the pipe (the calling process and prog2). Even if one of > them dies, there's always the possibility that the caller might eventually > decide to read prog1.stdout itself.

Re: subprocess.Popen does not close pipe in an error case

2010-01-06 Thread Nobody
On Tue, 05 Jan 2010 15:50:39 -0800, Steven K. Wong wrote: > Below, I have a Python script that launches 2 child programs, prog1 > and prog2, with prog1's stdout connected to prog2's stdin via a pipe. > (It's like executing "prog1 | prog2" in the shell.) > > If both child programs exit with 0, the

Re: subprocess.Popen does not close pipe in an error case

2010-01-05 Thread Steven K. Wong
BTW, I'm using Python 2.6.2 on Linux. -- http://mail.python.org/mailman/listinfo/python-list

subprocess.Popen does not close pipe in an error case

2010-01-05 Thread Steven K. Wong
Below, I have a Python script that launches 2 child programs, prog1 and prog2, with prog1's stdout connected to prog2's stdin via a pipe. (It's like executing "prog1 | prog2" in the shell.) If both child programs exit with 0, then the script runs to completion. But if prog2 exits with non-0, prog1