From 3340c3971f7663fb8a1a04c676f4a7cf734d1f0f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Tue, 10 Oct 2023 20:39:25 -0400 Subject: [PATCH] test: Close the thread pool in run_on_executor test 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 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tornado/test/circlerefs_test.py b/tornado/test/circlerefs_test.py index 5c71858ff..5c25adffd 100644 --- a/tornado/test/circlerefs_test.py +++ b/tornado/test/circlerefs_test.py @@ -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()) -- 2.47.2