popen2,3,4 -- will closing all returned streams result in process termination?

Discussion in 'Python' started by Evgeni Sergeev, Dec 28, 2004.

  1. After I opened streams to a process using popen2, popen3 or popen4,
    will closing every one of the streams terminate the process?

    Is there assurance that the process will terminate and not sit
    in memory orphaned, waiting on its stdin, for example?

    Evgeni Sergeev
     
    Evgeni Sergeev, Dec 28, 2004
    #1
    1. Advertising

  2. Evgeni Sergeev

    Paul Rubin Guest

    (Evgeni Sergeev) writes:
    > Is there assurance that the process will terminate and not sit
    > in memory orphaned, waiting on its stdin, for example?


    The process should receive an EOF. It will typically handle EOF by
    terminating, but that is not guaranteed.
     
    Paul Rubin, Dec 28, 2004
    #2
    1. Advertising

  3. It depends mostly on how the spawned process handles conditions like
    closed pipes, EOF, etc.

    In general and on *nix, any spawned and terminated process will become
    and remain a zombie until "reaped", i.e. until the final status is
    collected by a calling os.waitpid().

    To avoid zombies, you should call the poll() or wait() method of the
    Popen3 object created for each spawned process or call os.waitpid().
    The problem is that the popen* functions only return the pipe objects
    and not the Popen3 instance nor the process id.

    Take a look at the source code of the popen2 module which is the file
    ..../Lib/popen2.py in your python installation. It is straightforward
    to create your own popen* functions and keep the Popen3 instance.

    /Jean Brouwers



    In article <>, Evgeni
    Sergeev <> wrote:

    > After I opened streams to a process using popen2, popen3 or popen4,
    > will closing every one of the streams terminate the process?
    >
    > Is there assurance that the process will terminate and not sit
    > in memory orphaned, waiting on its stdin, for example?
    >
    > Evgeni Sergeev
     
    Jean Brouwers, Dec 28, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page