MCPcopy
hub / github.com/python-trio/trio / _finalize_one

Method _finalize_one

src/trio/_core/_asyncgens.py:223–243  ·  view source on GitHub ↗
(
        self,
        agen: AsyncGeneratorType[object, NoReturn],
        name: object,
    )

Source from the content-addressed store, hash-verified

221 sys.set_asyncgen_hooks(*self.prev_hooks)
222
223 async def _finalize_one(
224 self,
225 agen: AsyncGeneratorType[object, NoReturn],
226 name: object,
227 ) -> None:
228 try:
229 # This shield ensures that finalize_asyncgen never exits
230 # with an exception, not even a Cancelled. The inside
231 # is cancelled so there's no deadlock risk.
232 with _core.CancelScope(shield=True) as cancel_scope:
233 cancel_scope.cancel(
234 reason="disallow async work when closing async generators during trio shutdown"
235 )
236 await agen.aclose()
237 except BaseException:
238 ASYNCGEN_LOGGER.exception(
239 "Exception ignored during finalization of async generator %r -- "
240 "surround your use of the generator in 'async with aclosing(...):' "
241 "to raise exceptions like this in the context where they're generated",
242 name,
243 )

Callers 1

finalize_remainingMethod · 0.95

Calls 2

cancelMethod · 0.80
acloseMethod · 0.45

Tested by

no test coverage detected