subprocess.Popen pipeline bug?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marko Rauhamaa

    subprocess.Popen pipeline bug?


    This tiny program hangs:

    =============== =============== =============== =============== ============
    #!/usr/bin/env python
    import subprocess
    a = subprocess.Pope n('cat',shell = True,stdin = subprocess.PIPE ,
    stdout = subprocess.PIPE )
    b = subprocess.Pope n('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:marko@pa cujo.net http://pacujo.net/marko/
  • Marko Rauhamaa

    #2
    Re: subprocess.Pope n pipeline bug?

    bryanjugglercry ptographer@yaho o.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:marko@pa cujo.net http://pacujo.net/marko/

    Comment

    Working...