subprocess leaves child living

Michael Bentley michael at jedimindworks.com
Wed Jun 6 00:41:47 CEST 2007


On Jun 5, 2007, at 5:13 PM, Michael Bentley wrote:

>
> On Jun 5, 2007, at 4:17 PM, Thomas Dybdahl Ahle wrote:
>
>> Den Tue, 05 Jun 2007 15:46:39 -0500 skrev Michael Bentley:
>>
>>> But actually *that* is an orphan process.  When a parent process  
>>> dies
>>> and the child continues to run, the child becomes an orphan and is
>>> adopted by init.  Orphan processes can be cleaned up on most
>>> Unices with
>>> 'init q' (or something very similar).
>>
>> Is it not possible to tell python that this process should not be
>> adopted
>> by init, but die with its parrent?
>> Just like terminals seem to do it..
>
> Well, the way you posed the original question:
>
>> from subprocess import Popen
>> popen = Popen(["ping", "google.com"])
>> from time import sleep
>> sleep(100)
>
> is really what adoption by init is designed to handle. Here you've
> created a child but have not waited for its return value.  Like a
> good adoptive parent, init will wait(2) for the child.
>
> I think if you really looked into it you'd find that the terminal had
> called wait(2) before it was killed.  Similarly, if you start a long-
> running subprocess in python and wait for it to return -- killing the
> parent will slaughter the child as well.

I guess I should have verified my suspicions before speaking up -- I  
was worng -- even if you are waiting for a return code, the child  
will persist as a child of init.

regards,
Michael
---
The Rules of Optimization are simple.
Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet.
                                  -Michael A. Jackson





More information about the Python-list mailing list