https://github.com/python/cpython/commit/1c641ff2c3e57acaae27d36b6b30839e585ac090
commit: 1c641ff2c3e57acaae27d36b6b30839e585ac090
branch: main
author: Shardul Deshpande <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-09-11T18:12:45+05:30
summary:
gh-157157: Make test_taskgroup_cancel_keeps_outer_cancellation deterministic
(#157158)
files:
M Lib/test/test_asyncio/test_taskgroups.py
diff --git a/Lib/test/test_asyncio/test_taskgroups.py
b/Lib/test/test_asyncio/test_taskgroups.py
index 1515672393816b4..252504c6afb3fbd 100644
--- a/Lib/test/test_asyncio/test_taskgroups.py
+++ b/Lib/test/test_asyncio/test_taskgroups.py
@@ -1200,11 +1200,17 @@ async def child(tg):
async def test_taskgroup_cancel_keeps_outer_cancellation(self):
# gh-155433: any cancellation from outside the group must propagate.
+ cancelling = asyncio.Event()
+ release = asyncio.Event()
+
async def child():
try:
await asyncio.sleep(10)
finally:
- await asyncio.sleep(0.1)
+ # The group is cancelling: it has cancelled its parent task
+ # and is waiting for this task to finish.
+ cancelling.set()
+ await release.wait()
async def body():
async with asyncio.TaskGroup() as tg:
@@ -1213,8 +1219,9 @@ async def body():
tg.cancel()
task = asyncio.create_task(body())
- await asyncio.sleep(0.01)
+ await cancelling.wait()
task.cancel('message')
+ release.set()
with self.assertRaises(asyncio.CancelledError) as cm:
await task
self.assertEqual('message', cm.exception.args[0])
_______________________________________________
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]