Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   popen2,3,4 -- will closing all returned streams result in process termination? (http://www.velocityreviews.com/forums/t339729-popen2-3-4-will-closing-all-returned-streams-result-in-process-termination.html)

Evgeni Sergeev 12-28-2004 09:32 AM

popen2,3,4 -- will closing all returned streams result in process termination?
 
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

Paul Rubin 12-28-2004 09:47 AM

Re: popen2,3,4 -- will closing all returned streams result in process termination?
 
evgeni.sergeev@gmail.com (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.

Jean Brouwers 12-28-2004 07:19 PM

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

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@posting.google.com >, Evgeni
Sergeev <evgeni.sergeev@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



All times are GMT. The time now is 03:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.