From: Ben Darnell Date: Wed, 11 Oct 2023 00:39:25 +0000 (-0400) Subject: test: Close the thread pool in run_on_executor test X-Git-Tag: v6.4.0b1~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3332%2Fhead;p=thirdparty%2Ftornado.git 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). --- 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())