]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128002: fix `test_all_tasks_different_thread` in asyncio (#129267)
authorKumar Aditya <kumaraditya@python.org>
Fri, 24 Jan 2025 17:40:24 +0000 (23:10 +0530)
committerGitHub <noreply@github.com>
Fri, 24 Jan 2025 17:40:24 +0000 (23:10 +0530)
Lib/test/test_asyncio/test_free_threading.py

index c91719cb577c2f00d0c77657585f943daa8adf81..6da398e77e77979cc166561427c0f32e57df6790 100644 (file)
@@ -62,9 +62,9 @@ class TestFreeThreading:
     def test_all_tasks_different_thread(self) -> None:
         loop = None
         started = threading.Event()
-
+        done = threading.Event() # used for main task not finishing early
         async def coro():
-            await asyncio.sleep(0.01)
+            await asyncio.Future()
 
         lock = threading.Lock()
         tasks = set()
@@ -77,6 +77,7 @@ class TestFreeThreading:
                 with lock:
                     asyncio.create_task(coro())
                     tasks = self.all_tasks(loop)
+            done.wait()
 
         runner = threading.Thread(target=lambda: asyncio.run(main()))
 
@@ -86,11 +87,14 @@ class TestFreeThreading:
                 self.assertSetEqual(tasks & self.all_tasks(loop), tasks)
 
         threads = [threading.Thread(target=check) for _ in range(10)]
-        threads.append(runner)
+        runner.start()
 
         with threading_helper.start_threads(threads):
             pass
 
+        done.set()
+        runner.join()
+
     def test_run_coroutine_threadsafe(self) -> None:
         results = []