summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 7a4671c..0235498 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2073,26 +2073,35 @@ def reap_threads(func):
threading_cleanup(*key)
return decorator
+
def reap_children():
"""Use this function at the end of test_main() whenever sub-processes
are started. This will help ensure that no extra children (zombies)
stick around to hog resources and create problems when looking
for refleaks.
"""
+ global environment_altered
+
+ # Need os.waitpid(-1, os.WNOHANG): Windows is not supported
+ if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):
+ return
+
# Reap all our dead child processes so we don't leave zombies around.
# These hog resources and might be causing some of the buildbots to die.
- if hasattr(os, 'waitpid'):
- any_process = -1
- while True:
- try:
- # This will raise an exception on Windows. That's ok.
- pid, status = os.waitpid(any_process, os.WNOHANG)
- if pid == 0:
- break
- print("Warning -- reap_children() reaped child process %s"
- % pid, file=sys.stderr)
- except:
- break
+ while True:
+ try:
+ # Read the exit status of any child process which already completed
+ pid, status = os.waitpid(-1, os.WNOHANG)
+ except OSError:
+ break
+
+ if pid == 0:
+ break
+
+ print("Warning -- reap_children() reaped child process %s"
+ % pid, file=sys.stderr)
+ environment_altered = True
+
@contextlib.contextmanager
def start_threads(threads, unlock=None):