From: Victor Stinner Date: Wed, 26 Jul 2017 03:05:09 +0000 (+0200) Subject: bpo-30845: Enhance test_concurrent_futures cleanup (#2564) (#2880) X-Git-Tag: v3.6.3rc1~203 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6f045224a03f9b5f940c80ee142a2a4b4a9c9d8;p=thirdparty%2FPython%2Fcpython.git 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 3df9dec425b0254df1cdf41922fd8d6b08bf47e4) --- diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 677743bb3898..a5b8c46f9495 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2053,7 +2053,6 @@ def reap_children(): stick around to hog resources and create problems when looking for refleaks. """ - # 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'): @@ -2064,6 +2063,8 @@ def reap_children(): 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 diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 23e95b212447..92a3ebdd886c 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -63,6 +63,8 @@ class ExecutorMixin: worker_count = 5 def setUp(self): + self._thread_cleanup = test.support.threading_setup() + self.t1 = time.time() try: self.executor = self.executor_type(max_workers=self.worker_count) @@ -72,11 +74,16 @@ class ExecutorMixin: def tearDown(self): self.executor.shutdown(wait=True) + self.executor = None + dt = time.time() - self.t1 if test.support.verbose: print("%.2fs" % dt, end=' ') 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): # Make sure that the executor is ready to do work before running the # tests. This should reduce the probability of timeouts in the tests.