mirror of
https://github.com/python/cpython.git
synced 2025-08-26 03:34:43 +00:00
gh-125472: Revert "gh-124958: fix asyncio.TaskGroup and _PyFuture refcycles (#12… (#125476)
Revert "gh-124958: fix asyncio.TaskGroup and _PyFuture refcycles (#124959)"
This reverts commit d5dbbf4372
.
This commit is contained in:
parent
187580d95c
commit
e99650b80a
5 changed files with 15 additions and 147 deletions
|
@ -66,20 +66,6 @@ class TaskGroup:
|
|||
return self
|
||||
|
||||
async def __aexit__(self, et, exc, tb):
|
||||
tb = None
|
||||
try:
|
||||
return await self._aexit(et, exc)
|
||||
finally:
|
||||
# Exceptions are heavy objects that can have object
|
||||
# cycles (bad for GC); let's not keep a reference to
|
||||
# a bunch of them. It would be nicer to use a try/finally
|
||||
# in __aexit__ directly but that introduced some diff noise
|
||||
self._parent_task = None
|
||||
self._errors = None
|
||||
self._base_error = None
|
||||
exc = None
|
||||
|
||||
async def _aexit(self, et, exc):
|
||||
self._exiting = True
|
||||
|
||||
if (exc is not None and
|
||||
|
@ -136,10 +122,7 @@ class TaskGroup:
|
|||
assert not self._tasks
|
||||
|
||||
if self._base_error is not None:
|
||||
try:
|
||||
raise self._base_error
|
||||
finally:
|
||||
exc = None
|
||||
raise self._base_error
|
||||
|
||||
if self._parent_cancel_requested:
|
||||
# If this flag is set we *must* call uncancel().
|
||||
|
@ -150,14 +133,8 @@ class TaskGroup:
|
|||
|
||||
# Propagate CancelledError if there is one, except if there
|
||||
# are other errors -- those have priority.
|
||||
try:
|
||||
if propagate_cancellation_error is not None and not self._errors:
|
||||
try:
|
||||
raise propagate_cancellation_error
|
||||
finally:
|
||||
exc = None
|
||||
finally:
|
||||
propagate_cancellation_error = None
|
||||
if propagate_cancellation_error is not None and not self._errors:
|
||||
raise propagate_cancellation_error
|
||||
|
||||
if et is not None and not issubclass(et, exceptions.CancelledError):
|
||||
self._errors.append(exc)
|
||||
|
@ -169,14 +146,14 @@ class TaskGroup:
|
|||
if self._parent_task.cancelling():
|
||||
self._parent_task.uncancel()
|
||||
self._parent_task.cancel()
|
||||
# Exceptions are heavy objects that can have object
|
||||
# cycles (bad for GC); let's not keep a reference to
|
||||
# a bunch of them.
|
||||
try:
|
||||
raise BaseExceptionGroup(
|
||||
'unhandled errors in a TaskGroup',
|
||||
self._errors,
|
||||
) from None
|
||||
me = BaseExceptionGroup('unhandled errors in a TaskGroup', self._errors)
|
||||
raise me from None
|
||||
finally:
|
||||
exc = None
|
||||
|
||||
self._errors = None
|
||||
|
||||
def create_task(self, coro, *, name=None, context=None):
|
||||
"""Create a new task in this group and return it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue