[3.13] gh-152569: Fix asyncio.wait leaking tasks via await-graph on long-lived futures (GH-152585) by miss-islington · Pull Request #152867 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/asyncio/tasks.py
13 changes: 13 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,19 @@ def gen():
loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b]))

def test_wait_discards_awaited_by_for_pending(self):
# gh-152569: wait() must remove itself from the await-graph of every
# future once it returns, including futures that never resolved.
async def coro():
immortal = self.loop.create_future()
done = self.new_task(self.loop, asyncio.sleep(0))
await asyncio.wait({done, immortal},
return_when=asyncio.FIRST_COMPLETED)
self.assertFalse(immortal._asyncio_awaited_by)
immortal.cancel()

self.loop.run_until_complete(self.new_task(self.loop, coro()))

def test_wait_really_done(self):
# there is possibility that some tasks in the pending list
# became done but their callbacks haven't all been called yet
Expand Down
Loading