Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Avoiding defunct processes (http://www.velocityreviews.com/forums/t954125-avoiding-defunct-processes.html)

Richard 11-02-2012 02:16 AM

Avoiding defunct processes
 
Hello,

I create child processes with subprocess.Popen().
Then I either wait for them to finish or kill them.
Either way these processes end up as defunct until the parent process
completes:
$ ps e
6851 pts/5 Z+ 1:29 [python] <defunct>

This confuses another library as to whether the processes are
complete.
For now I detect which processes are defunct by parsing the output of
"ps".
What would you recommend? I am hoping there is a cleaner way.

Richard

Chris Angelico 11-02-2012 02:36 AM

Re: Avoiding defunct processes
 
On Fri, Nov 2, 2012 at 1:16 PM, Richard <richardbp@gmail.com> wrote:
> Hello,
>
> I create child processes with subprocess.Popen().
> Then I either wait for them to finish or kill them.
> Either way these processes end up as defunct until the parent process
> completes:
> $ ps e
> 6851 pts/5 Z+ 1:29 [python] <defunct>
>
> This confuses another library as to whether the processes are
> complete.
> For now I detect which processes are defunct by parsing the output of
> "ps".
> What would you recommend? I am hoping there is a cleaner way.


That's a zombie process, it's finished but the parent hasn't wait()ed
for it yet.

http://docs.python.org/3.3/library/s...ess.Popen.wait

Once the process has ended, call that to get its return value and
clean everything up.

ChrisA

Nobody 11-02-2012 03:46 PM

Re: Avoiding defunct processes
 
On Thu, 01 Nov 2012 19:16:17 -0700, Richard wrote:

> I create child processes with subprocess.Popen().
> Then I either wait for them to finish or kill them.
> Either way these processes end up as defunct until the parent process
> completes:
> $ ps e
> 6851 pts/5 Z+ 1:29 [python] <defunct>


You need to either call the .wait() method, or keep calling the .poll()
method until the .returncode attribute is not None.



All times are GMT. The time now is 12:47 PM.

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