]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raising...
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Sat, 22 Oct 2022 16:05:11 +0000 (21:35 +0530)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 16:05:11 +0000 (09:05 -0700)
Lib/asyncio/taskgroups.py

index 5d5e2a8a85dd482611373deb573937a23b3d1bfb..911419e1769c17ad53d931bacc4575eefd3660a9 100644 (file)
@@ -128,11 +128,11 @@ class TaskGroup:
             # 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: