gh-125472: Revert "gh-124958: fix asyncio.TaskGroup and _PyFuture ref… · python/cpython@1114111 (original) (raw)

`@@ -66,20 +66,6 @@ async def aenter(self):

`

66

66

`return self

`

67

67

``

68

68

`async def aexit(self, et, exc, tb):

`

69

``

`-

tb = None

`

70

``

`-

try:

`

71

``

`-

return await self._aexit(et, exc)

`

72

``

`-

finally:

`

73

``

`-

Exceptions are heavy objects that can have object

`

74

``

`-

cycles (bad for GC); let's not keep a reference to

`

75

``

`-

a bunch of them. It would be nicer to use a try/finally

`

76

``

`-

in aexit directly but that introduced some diff noise

`

77

``

`-

self._parent_task = None

`

78

``

`-

self._errors = None

`

79

``

`-

self._base_error = None

`

80

``

`-

exc = None

`

81

``

-

82

``

`-

async def _aexit(self, et, exc):

`

83

69

`self._exiting = True

`

84

70

``

85

71

`if (exc is not None and

`

`@@ -136,10 +122,7 @@ async def _aexit(self, et, exc):

`

136

122

`assert not self._tasks

`

137

123

``

138

124

`if self._base_error is not None:

`

139

``

`-

try:

`

140

``

`-

raise self._base_error

`

141

``

`-

finally:

`

142

``

`-

exc = None

`

``

125

`+

raise self._base_error

`

143

126

``

144

127

`if self._parent_cancel_requested:

`

145

128

`# If this flag is set we must call uncancel().

`

`@@ -150,14 +133,8 @@ async def _aexit(self, et, exc):

`

150

133

``

151

134

`# Propagate CancelledError if there is one, except if there

`

152

135

`# are other errors -- those have priority.

`

153

``

`-

try:

`

154

``

`-

if propagate_cancellation_error is not None and not self._errors:

`

155

``

`-

try:

`

156

``

`-

raise propagate_cancellation_error

`

157

``

`-

finally:

`

158

``

`-

exc = None

`

159

``

`-

finally:

`

160

``

`-

propagate_cancellation_error = None

`

``

136

`+

if propagate_cancellation_error is not None and not self._errors:

`

``

137

`+

raise propagate_cancellation_error

`

161

138

``

162

139

`if et is not None and not issubclass(et, exceptions.CancelledError):

`

163

140

`self._errors.append(exc)

`

`@@ -169,14 +146,14 @@ async def _aexit(self, et, exc):

`

169

146

`if self._parent_task.cancelling():

`

170

147

`self._parent_task.uncancel()

`

171

148

`self._parent_task.cancel()

`

``

149

`+

Exceptions are heavy objects that can have object

`

``

150

`+

cycles (bad for GC); let's not keep a reference to

`

``

151

`+

a bunch of them.

`

172

152

`try:

`

173

``

`-

raise BaseExceptionGroup(

`

174

``

`-

'unhandled errors in a TaskGroup',

`

175

``

`-

self._errors,

`

176

``

`-

) from None

`

``

153

`+

me = BaseExceptionGroup('unhandled errors in a TaskGroup', self._errors)

`

``

154

`+

raise me from None

`

177

155

`finally:

`

178

``

`-

exc = None

`

179

``

-

``

156

`+

self._errors = None

`

180

157

``

181

158

`def create_task(self, coro, *, name=None, context=None):

`

182

159

`"""Create a new task in this group and return it.

`