bpo-41891: ensure asyncio.wait_for waits for task completion (GH-22461) (#23840)

(cherry picked from commit 17ef4319a3)

Co-authored-by: Richard Kojedzinszky <rkojedzinszky@users.noreply.github.com>

Co-authored-by: Richard Kojedzinszky <rkojedzinszky@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2020-12-18 11:19:10 -08:00 committed by GitHub
parent 14619924c3
commit 82dbfd5a04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View file

@ -471,7 +471,10 @@ async def wait_for(fut, timeout, *, loop=None):
return fut.result()
else:
fut.remove_done_callback(cb)
fut.cancel()
# We must ensure that the task is not running
# after wait_for() returns.
# See https://bugs.python.org/issue32751
await _cancel_and_wait(fut, loop=loop)
raise
if fut.done():