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

Jean Brouwers mrjean1ATcomcastDOTnet at no.spam.net
Tue Dec 28 20:19:57 CET 2004


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 <88795ffc.0412280132.5f84ac0d at posting.google.com>, Evgeni
Sergeev <evgeni.sergeev at gmail.com> 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



More information about the Python-list mailing list