467,072 Members | 1,238 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,072 developers. It's quick & easy.

subprocess.Popen pipeline bug?


This tiny program hangs:

================================================== ======================
#!/usr/bin/env python
import subprocess
a = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
b = subprocess.Popen('cat >/dev/null',shell = True,stdin = a.stdout)
a.stdin.close()
b.wait() # hangs
a.wait() # never reached
================================================== ======================

It shouldn't, should it?

Environment:
================================================== ======================
Python 2.5.1 (r251:54863, Jun 20 2007, 12:14:09)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
================================================== ======================
Marko

--
Marko Rauhamaa mailto:ma***@pacujo.net http://pacujo.net/marko/
Mar 13 '08 #1
  • viewed: 1741
Share:
1 Reply
br***********************@yahoo.com:
Not sure. I think what's happening is that the second cat subprocess
never gets EOF on its stdin, because there are still processes with an
open file descriptor for the other end of the pipe.
You are right. However, the close_fds technique seems a bit
heavy-handed. Well, that's what you get when you try to combine fork and
exec into a single call.
Marko

--
Marko Rauhamaa mailto:ma***@pacujo.net http://pacujo.net/marko/
Mar 13 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by George Sakkis | last post: by
12 posts views Thread by Eric_Dexter@msn.com | last post: by
11 posts views Thread by 7stud | last post: by
9 posts views Thread by Phoe6 | last post: by
reply views Thread by Joe Blow | last post: by
7 posts views Thread by skunkwerk | last post: by
25 posts views Thread by Jeremy Banks | last post: by
1 post views Thread by Mark Shewfelt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.