mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209)
This commit is contained in:
parent
1cee216cf3
commit
863b674909
4 changed files with 46 additions and 2 deletions
|
@ -2037,7 +2037,7 @@ class BaseTaskTests:
|
|||
def test_cancel_wait_for(self):
|
||||
self._test_cancel_wait_for(60.0)
|
||||
|
||||
def test_cancel_gather(self):
|
||||
def test_cancel_gather_1(self):
|
||||
"""Ensure that a gathering future refuses to be cancelled once all
|
||||
children are done"""
|
||||
loop = asyncio.new_event_loop()
|
||||
|
@ -2067,6 +2067,33 @@ class BaseTaskTests:
|
|||
self.assertFalse(gather_task.cancelled())
|
||||
self.assertEqual(gather_task.result(), [42])
|
||||
|
||||
def test_cancel_gather_2(self):
|
||||
loop = asyncio.new_event_loop()
|
||||
self.addCleanup(loop.close)
|
||||
|
||||
async def test():
|
||||
time = 0
|
||||
while True:
|
||||
time += 0.05
|
||||
await asyncio.gather(asyncio.sleep(0.05),
|
||||
return_exceptions=True,
|
||||
loop=loop)
|
||||
if time > 1:
|
||||
return
|
||||
|
||||
async def main():
|
||||
qwe = asyncio.Task(test())
|
||||
await asyncio.sleep(0.2)
|
||||
qwe.cancel()
|
||||
try:
|
||||
await qwe
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
else:
|
||||
self.fail('gather did not propagate the cancellation request')
|
||||
|
||||
loop.run_until_complete(main())
|
||||
|
||||
def test_exception_traceback(self):
|
||||
# See http://bugs.python.org/issue28843
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue