Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3df9dec

Browse files
authoredJul 4, 2017
bpo-30845: Enhance test_concurrent_futures cleanup (#2564)
* bpo-30845: reap_children() now logs warnings * bpo-30845: Enhance test_concurrent_futures cleanup In setUp() and tearDown() methods of test_concurrent_futures tests, make sure that tests don't leak threads nor processes. Clear explicitly the reference to the executor to make it that it's destroyed (to prevent "dangling threads" warning).
1 parent 4835041 commit 3df9dec

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎Lib/test/support/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,6 @@ def reap_children():
20792079
stick around to hog resources and create problems when looking
20802080
for refleaks.
20812081
"""
2082-
20832082
# Reap all our dead child processes so we don't leave zombies around.
20842083
# These hog resources and might be causing some of the buildbots to die.
20852084
if hasattr(os, 'waitpid'):
@@ -2090,6 +2089,8 @@ def reap_children():
20902089
pid, status = os.waitpid(any_process, os.WNOHANG)
20912090
if pid == 0:
20922091
break
2092+
print("Warning -- reap_children() reaped child process %s"
2093+
% pid, file=sys.stderr)
20932094
except:
20942095
break
20952096

‎Lib/test/test_concurrent_futures.py

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class ExecutorMixin:
6363
worker_count = 5
6464

6565
def setUp(self):
66+
self._thread_cleanup = test.support.threading_setup()
67+
6668
self.t1 = time.time()
6769
try:
6870
self.executor = self.executor_type(max_workers=self.worker_count)
@@ -72,11 +74,16 @@ def setUp(self):
7274

7375
def tearDown(self):
7476
self.executor.shutdown(wait=True)
77+
self.executor = None
78+
7579
dt = time.time() - self.t1
7680
if test.support.verbose:
7781
print("%.2fs" % dt, end=' ')
7882
self.assertLess(dt, 60, "synchronization issue: test lasted too long")
7983

84+
test.support.threading_cleanup(*self._thread_cleanup)
85+
test.support.reap_children()
86+
8087
def _prime_executor(self):
8188
# Make sure that the executor is ready to do work before running the
8289
# tests. This should reduce the probability of timeouts in the tests.

0 commit comments

Comments
 (0)
Please sign in to comment.