[Python-checkins] GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raising ExceptionGroup (#98544)
gvanrossum
webhook-mailer at python.org
Sat Oct 22 12:05:16 EDT 2022
https://github.com/python/cpython/commit/f4a14941e6e54b15012fca067f6a9b2ff29f201a
commit: f4a14941e6e54b15012fca067f6a9b2ff29f201a
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-10-22T09:05:11-07:00
summary:
GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raising ExceptionGroup (#98544)
files:
M Lib/asyncio/taskgroups.py
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 5d5e2a8a85dd..911419e1769c 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -128,11 +128,11 @@ async def __aexit__(self, et, exc, tb):
# Exceptions are heavy objects that can have object
# cycles (bad for GC); let's not keep a reference to
# a bunch of them.
- errors = self._errors
- self._errors = None
-
- me = BaseExceptionGroup('unhandled errors in a TaskGroup', errors)
- raise me from None
+ try:
+ me = BaseExceptionGroup('unhandled errors in a TaskGroup', self._errors)
+ raise me from None
+ finally:
+ self._errors = None
def create_task(self, coro, *, name=None, context=None):
if not self._entered:
More information about the Python-checkins
mailing list