Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Avoiding defunct processes

292 views
Skip to first unread message

Richard

unread,
Nov 1, 2012, 10:16:17 PM11/1/12
to
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

unread,
Nov 1, 2012, 10:36:40 PM11/1/12
to pytho...@python.org
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

Nobody

unread,
Nov 2, 2012, 11:46:04 AM11/2/12
to
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.

0 new messages