]> git.ipfire.org Git - thirdparty/tornado.git/commit
gen: Hold strong references to all asyncio.Tasks 3269/head
authorBen Darnell <ben@bendarnell.com>
Mon, 15 May 2023 01:03:52 +0000 (21:03 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 15 May 2023 01:03:52 +0000 (21:03 -0400)
commitbffed1aaed56ca29eb1dd261afc2a8bb1380cd7a
tree18499ff20c39a447d6f063447dc4041085d73b74
parentf41d78dccb55d7ff632dfdb62024cc9934e6a024
gen: Hold strong references to all asyncio.Tasks

Per the warning in the asyncio documentation, we need to hold a strong
reference to all asyncio Tasks to prevent premature GC. Following
discussions in cpython (https://github.com/python/cpython/issues/91887),
we hold these references on the IOLoop instance to ensure that they are
strongly held but do not cause leaks if the event loop itself is
discarded.

This is expected to fix all of the various "task was destroyed but
it is pending" warnings that have been reported. The
IOLoop._pending_tasks set is expected to become obsolete if
corresponding changes are made to asyncio in Python 3.13.

Fixes #3209
Fixes #3047
Fixes #2763

Some issues involve this warning as their most visible symptom,
but have an underlying cause that should still be addressed.
Updates #2914
Updates #2356
tornado/gen.py
tornado/ioloop.py