@@ -1991,7 +1991,7 @@ def test_cancel_blocking_wait_for(self):
19911991 def test_cancel_wait_for (self ):
19921992 self ._test_cancel_wait_for (60.0 )
19931993
1994- def test_cancel_gather (self ):
1994+ def test_cancel_gather_1 (self ):
19951995 """Ensure that a gathering future refuses to be cancelled once all
19961996 children are done"""
19971997 loop = asyncio .new_event_loop ()
@@ -2021,6 +2021,33 @@ def cancelling_callback(_):
20212021 self .assertFalse (gather_task .cancelled ())
20222022 self .assertEqual (gather_task .result (), [42 ])
20232023
2024+ def test_cancel_gather_2 (self ):
2025+ loop = asyncio .new_event_loop ()
2026+ self .addCleanup (loop .close )
2027+
2028+ async def test ():
2029+ time = 0
2030+ while True :
2031+ time += 0.05
2032+ await asyncio .gather (asyncio .sleep (0.05 , loop = loop ),
2033+ return_exceptions = True ,
2034+ loop = loop )
2035+ if time > 1 :
2036+ return
2037+
2038+ async def main ():
2039+ qwe = self .new_task (loop , test ())
2040+ await asyncio .sleep (0.2 , loop = loop )
2041+ qwe .cancel ()
2042+ try :
2043+ await qwe
2044+ except asyncio .CancelledError :
2045+ pass
2046+ else :
2047+ self .fail ('gather did not propagate the cancellation request' )
2048+
2049+ loop .run_until_complete (main ())
2050+
20242051 def test_exception_traceback (self ):
20252052 # See http://bugs.python.org/issue28843
20262053
0 commit comments