Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Avoiding defunct processes

Reply
Thread Tools

Avoiding defunct processes

 
 
Richard
Guest
Posts: n/a
 
      11-02-2012
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
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      11-02-2012
On Fri, Nov 2, 2012 at 1:16 PM, Richard <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      11-02-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Daemon Server, Forking, Defunct Processes Scottman C Programming 2 09-11-2008 03:11 PM
Defunct Processes With subprocess.Popen John Abel Python 2 05-12-2005 07:53 AM
Script to kill defunct and zombie processes Srini Vuggumudi Perl Misc 4 05-01-2004 12:14 AM
Script to kill defunct and zombie processes Srini Vuggumudi Perl Misc 0 04-29-2004 07:53 PM
<defunct> processes Gordon Beaton Java 4 11-07-2003 06:18 PM



Advertisments