File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1200,11 +1200,17 @@ async def child(tg):
12001200
12011201 async def test_taskgroup_cancel_keeps_outer_cancellation (self ):
12021202 # gh-155433: any cancellation from outside the group must propagate.
1203+ cancelling = asyncio .Event ()
1204+ release = asyncio .Event ()
1205+
12031206 async def child ():
12041207 try :
12051208 await asyncio .sleep (10 )
12061209 finally :
1207- await asyncio .sleep (0.1 )
1210+ # The group is cancelling: it has cancelled its parent task
1211+ # and is waiting for this task to finish.
1212+ cancelling .set ()
1213+ await release .wait ()
12081214
12091215 async def body ():
12101216 async with asyncio .TaskGroup () as tg :
@@ -1213,8 +1219,9 @@ async def body():
12131219 tg .cancel ()
12141220
12151221 task = asyncio .create_task (body ())
1216- await asyncio . sleep ( 0.01 )
1222+ await cancelling . wait ( )
12171223 task .cancel ('message' )
1224+ release .set ()
12181225 with self .assertRaises (asyncio .CancelledError ) as cm :
12191226 await task
12201227 self .assertEqual ('message' , cm .exception .args [0 ])
You can’t perform that action at this time.
0 commit comments