https://github.com/python/cpython/commit/e635bf2e49797ecb976ce45a67fce2201a25ca68
commit: e635bf2e49797ecb976ce45a67fce2201a25ca68
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-01-24T23:10:24+05:30
summary:
gh-128002: fix `test_all_tasks_different_thread` in asyncio (#129267)
files:
M Lib/test/test_asyncio/test_free_threading.py
diff --git a/Lib/test/test_asyncio/test_free_threading.py
b/Lib/test/test_asyncio/test_free_threading.py
index c91719cb577c2f..6da398e77e7797 100644
--- a/Lib/test/test_asyncio/test_free_threading.py
+++ b/Lib/test/test_asyncio/test_free_threading.py
@@ -62,9 +62,9 @@ def runner():
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 @@ async def main():
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 @@ def check():
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 = []
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]