Kaydet (Commit) 3df9dec4 authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

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).
üst 48350412
...@@ -2079,7 +2079,6 @@ def reap_children(): ...@@ -2079,7 +2079,6 @@ def reap_children():
stick around to hog resources and create problems when looking stick around to hog resources and create problems when looking
for refleaks. for refleaks.
""" """
# Reap all our dead child processes so we don't leave zombies around. # 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. # These hog resources and might be causing some of the buildbots to die.
if hasattr(os, 'waitpid'): if hasattr(os, 'waitpid'):
...@@ -2090,6 +2089,8 @@ def reap_children(): ...@@ -2090,6 +2089,8 @@ def reap_children():
pid, status = os.waitpid(any_process, os.WNOHANG) pid, status = os.waitpid(any_process, os.WNOHANG)
if pid == 0: if pid == 0:
break break
print("Warning -- reap_children() reaped child process %s"
% pid, file=sys.stderr)
except: except:
break break
......
...@@ -63,6 +63,8 @@ class ExecutorMixin: ...@@ -63,6 +63,8 @@ class ExecutorMixin:
worker_count = 5 worker_count = 5
def setUp(self): def setUp(self):
self._thread_cleanup = test.support.threading_setup()
self.t1 = time.time() self.t1 = time.time()
try: try:
self.executor = self.executor_type(max_workers=self.worker_count) self.executor = self.executor_type(max_workers=self.worker_count)
...@@ -72,11 +74,16 @@ class ExecutorMixin: ...@@ -72,11 +74,16 @@ class ExecutorMixin:
def tearDown(self): def tearDown(self):
self.executor.shutdown(wait=True) self.executor.shutdown(wait=True)
self.executor = None
dt = time.time() - self.t1 dt = time.time() - self.t1
if test.support.verbose: if test.support.verbose:
print("%.2fs" % dt, end=' ') print("%.2fs" % dt, end=' ')
self.assertLess(dt, 60, "synchronization issue: test lasted too long") self.assertLess(dt, 60, "synchronization issue: test lasted too long")
test.support.threading_cleanup(*self._thread_cleanup)
test.support.reap_children()
def _prime_executor(self): def _prime_executor(self):
# Make sure that the executor is ready to do work before running the # Make sure that the executor is ready to do work before running the
# tests. This should reduce the probability of timeouts in the tests. # tests. This should reduce the probability of timeouts in the tests.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment