]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
test: Close the thread pool in run_on_executor test 3332/head
authorBen Darnell <ben@bendarnell.com>
Wed, 11 Oct 2023 00:39:25 +0000 (20:39 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 14 Oct 2023 02:47:35 +0000 (22:47 -0400)
If this executor was left around it would be GC'd at an unpredictable
time and would often be reported as a failure in other circlerefs tests.
(For unknown reasons this would occur most often in i686 (i.e. 32-bit)
linux builds).

tornado/test/circlerefs_test.py

index 5c71858ff72d1ee57588903174d5854e25e7f480..5c25adffd830696041dc62ded7313a591c09cc6c 100644 (file)
@@ -197,21 +197,21 @@ class CircleRefsTest(unittest.TestCase):
         # and tornado.concurrent.chain_future.
         import concurrent.futures
 
-        thread_pool = concurrent.futures.ThreadPoolExecutor(1)
+        with concurrent.futures.ThreadPoolExecutor(1) as thread_pool:
 
-        class Factory(object):
-            executor = thread_pool
+            class Factory(object):
+                executor = thread_pool
 
-            @tornado.concurrent.run_on_executor
-            def run(self):
-                return None
+                @tornado.concurrent.run_on_executor
+                def run(self):
+                    return None
 
-        factory = Factory()
+            factory = Factory()
 
-        async def main():
-            # The cycle is not reported on the first call. It's not clear why.
-            for i in range(2):
-                await factory.run()
+            async def main():
+                # The cycle is not reported on the first call. It's not clear why.
+                for i in range(2):
+                    await factory.run()
 
-        with assert_no_cycle_garbage():
-            asyncio.run(main())
+            with assert_no_cycle_garbage():
+                asyncio.run(main())