(
self,
agen: AsyncGeneratorType[object, NoReturn],
name: object,
)
| 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 | ) |
no test coverage detected