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

E

Evgeni Sergeev

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
 
P

Paul Rubin

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.
 
J

Jean Brouwers

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top