diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-09-01 12:46:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 12:46:44 (GMT) |
commit | 60f3f1fb5cbf5354c3081138be806c56cb04153f (patch) | |
tree | 9c2a2dd924700930d3a757c32809a768af0a5caa /Lib/test | |
parent | b5db7bb9da1120912a1795fbc6106d0eba5a01c7 (diff) | |
download | cpython-60f3f1fb5cbf5354c3081138be806c56cb04153f.zip cpython-60f3f1fb5cbf5354c3081138be806c56cb04153f.tar.gz cpython-60f3f1fb5cbf5354c3081138be806c56cb04153f.tar.bz2 |
bpo-31249: Fix ref cycle in ThreadPoolExecutor (#3253)
[3.6] bpo-31249: Fix ref cycle in ThreadPoolExecutor
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 92a3ebd..90dec61 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -59,11 +59,20 @@ class MyObject(object): pass +class BaseTestCase(unittest.TestCase): + def setUp(self): + self._thread_key = test.support.threading_setup() + + def tearDown(self): + test.support.reap_children() + test.support.threading_cleanup(*self._thread_key) + + class ExecutorMixin: worker_count = 5 def setUp(self): - self._thread_cleanup = test.support.threading_setup() + super().setUp() self.t1 = time.time() try: @@ -81,8 +90,7 @@ class ExecutorMixin: 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() + super().tearDown() def _prime_executor(self): # Make sure that the executor is ready to do work before running the @@ -130,7 +138,7 @@ class ExecutorShutdownTest: f.result() -class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, unittest.TestCase): +class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, BaseTestCase): def _prime_executor(self): pass @@ -186,7 +194,7 @@ class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, unittest.Tes t.join() -class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest, unittest.TestCase): +class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest, BaseTestCase): def _prime_executor(self): pass @@ -323,7 +331,7 @@ class WaitTests: self.assertEqual(set([future2]), pending) -class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, unittest.TestCase): +class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase): def test_pending_calls_race(self): # Issue #14406: multi-threaded race condition when waiting on all @@ -341,7 +349,7 @@ class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, unittest.TestCase): sys.setswitchinterval(oldswitchinterval) -class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, unittest.TestCase): +class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, BaseTestCase): pass @@ -390,11 +398,11 @@ class AsCompletedTests: self.assertEqual(len(completed), 1) -class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests, unittest.TestCase): +class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests, BaseTestCase): pass -class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests, unittest.TestCase): +class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests, BaseTestCase): pass @@ -465,7 +473,7 @@ class ExecutorTest: self.executor_type(max_workers=number) -class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, unittest.TestCase): +class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, BaseTestCase): def test_map_submits_without_iteration(self): """Tests verifying issue 11777.""" finished = [] @@ -482,7 +490,7 @@ class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, unittest.TestCase): (os.cpu_count() or 1) * 5) -class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, unittest.TestCase): +class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, BaseTestCase): def test_killed_child(self): # When a child process is abruptly terminated, the whole pool gets # "broken". @@ -538,7 +546,7 @@ class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, unittest.TestCase) f1.getvalue()) -class FutureTests(unittest.TestCase): +class FutureTests(BaseTestCase): def test_done_callback_with_result(self): callback_result = None def fn(callback_future): |