By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

subprocess.Popen pipeline bug?

P: n/a

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
Share this Question
Share on Google+
1 Reply


P: n/a
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.