Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32590 > unrolled thread

Avoiding defunct processes

Started byRichard <richardbp@gmail.com>
First post2012-11-01 19:16 -0700
Last post2012-11-02 15:46 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Avoiding defunct processes Richard <richardbp@gmail.com> - 2012-11-01 19:16 -0700
    Re: Avoiding defunct processes Chris Angelico <rosuav@gmail.com> - 2012-11-02 13:36 +1100
    Re: Avoiding defunct processes Nobody <nobody@nowhere.com> - 2012-11-02 15:46 +0000

#32590 — Avoiding defunct processes

FromRichard <richardbp@gmail.com>
Date2012-11-01 19:16 -0700
SubjectAvoiding defunct processes
Message-ID<b8d1fb3a-20cd-4889-900a-61ec5b64f0c1@uc4g2000pbc.googlegroups.com>
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

[toc] | [next] | [standalone]


#32591

FromChris Angelico <rosuav@gmail.com>
Date2012-11-02 13:36 +1100
Message-ID<mailman.3175.1351823803.27098.python-list@python.org>
In reply to#32590
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/subprocess.html#subprocess.Popen.wait

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

ChrisA

[toc] | [prev] | [next] | [standalone]


#32635

FromNobody <nobody@nowhere.com>
Date2012-11-02 15:46 +0000
Message-ID<pan.2012.11.02.15.46.04.75000@nowhere.com>
In reply to#32590
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web