From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 24 Oct 2022 18:08:22 +0000 (-0700) Subject: [3.11] GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raisi... X-Git-Tag: v3.11.1~221 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=36d25a4f7f8263cac9f8609e0347d4060d1dce3b;p=thirdparty%2FPython%2Fcpython.git [3.11] GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raising ExceptionGroup (GH-98544) (#98550) GH-98543: Fix `asyncio.TaskGroup` to not keep reference to errors after raising ExceptionGroup (GH-98544) (cherry picked from commit f4a14941e6e54b15012fca067f6a9b2ff29f201a) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- 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 @@ 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: