summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-15 16:31:23 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-15 16:31:23 +0200
commit1514fcb8dff4ca911a4431f8c5969383c65922ef (patch)
tree5766bc2bb5090655054bfc73043d786054950cc4
parente780cd448b0360cbf19657c242bc1ec7535114c3 (diff)
downloadpsutil-1514fcb8dff4ca911a4431f8c5969383c65922ef.tar.gz
refactor reap_children
-rw-r--r--psutil/tests/__init__.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index cf90a63c..c3ba1a43 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -252,13 +252,16 @@ def sh(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
def reap_children(recursive=False):
- """Kill any subprocess started by this test suite and ensure that
- no zombies stick around to hog resources and create problems when
- looking for refleaks.
+ """Terminate and wait() any subprocess started by this test suite
+ and ensure that no zombies stick around to hog resources and
+ create problems when looking for refleaks.
+
+ If resursive is True it also tries to terminate and wait()
+ all grandchildren started by this process.
"""
- # Get the children here, before terminating the sub processes
- # as we don't want to lose the intermediate reference in case
- # of grand children.
+ # Get the children here, before terminating the children sub
+ # processes as we don't want to lose the intermediate reference
+ # in case of grandchildren.
if recursive:
children = psutil.Process().children(recursive=True)
else:
@@ -290,6 +293,7 @@ def reap_children(recursive=False):
if err.errno != errno.ECHILD:
raise
+ # Terminates grandchildren.
if children:
for p in children:
try:
@@ -298,14 +302,15 @@ def reap_children(recursive=False):
pass
gone, alive = psutil.wait_procs(children, timeout=GLOBAL_TIMEOUT)
for p in alive:
- warn("couldn't terminate process %s" % p)
+ warn("couldn't terminate process %r; attempting kill()" % p)
try:
p.kill()
except psutil.NoSuchProcess:
pass
- _, alive = psutil.wait_procs(alive, timeout=GLOBAL_TIMEOUT)
- if alive:
- warn("couldn't not kill processes %s" % str(alive))
+ _, alive = psutil.wait_procs(alive, timeout=GLOBAL_TIMEOUT)
+ if alive:
+ for p in alive:
+ warn("process %r survived kill()" % p)
# ===================================================================