Skip to content

Commit a6f0452

Browse files
authored
bpo-30845: Enhance test_concurrent_futures cleanup (#2564) (#2880)
* 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). (cherry picked from commit 3df9dec)
1 parent d0adfb2 commit a6f0452

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,6 @@ def reap_children():
20532053
stick around to hog resources and create problems when looking
20542054
for refleaks.
20552055
"""
2056-
20572056
# Reap all our dead child processes so we don't leave zombies around.
20582057
# These hog resources and might be causing some of the buildbots to die.
20592058
if hasattr(os, 'waitpid'):
@@ -2064,6 +2063,8 @@ def reap_children():
20642063
pid, status = os.waitpid(any_process, os.WNOHANG)
20652064
if pid == 0:
20662065
break
2066+
print("Warning -- reap_children() reaped child process %s"
2067+
% pid, file=sys.stderr)
20672068
except:
20682069
break
20692070

Lib/test/test_concurrent_futures.py

Lines changed: 7 additions & 0 deletions
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)