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

This commit is contained in:
Thomas Grainger 2025-01-07 11:44:57 +00:00 committed by GitHub
parent 6ea04da270
commit 61b9811ac6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 71 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