[3.13] gh-128552: fix refcycles in eager task creation (#128553) (#128585)

gh-128552: fix refcycles in eager task creation (#128553)

(cherry picked from commit 61b9811ac6)
This commit is contained in:
Thomas Grainger 2025-01-08 12:46:43 +00:00 committed by GitHub
parent 7e099c51b6
commit 13835888e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 72 additions and 6 deletions

View file

@ -205,7 +205,12 @@ class TaskGroup:
else:
self._tasks.add(task)
task.add_done_callback(self._on_task_done)
return task
try:
return task
finally:
# gh-128552: prevent a refcycle of
# task.exception().__traceback__->TaskGroup.create_task->task
del task
# Since Python 3.8 Tasks propagate all exceptions correctly,
# except for KeyboardInterrupt and SystemExit which are