_resources.py 435 B

123456789101112131415161718
  1. from __future__ import annotations
  2. from ..abc import AsyncResource
  3. from ._tasks import CancelScope
  4. async def aclose_forcefully(resource: AsyncResource) -> None:
  5. """
  6. Close an asynchronous resource in a cancelled scope.
  7. Doing this closes the resource without waiting on anything.
  8. :param resource: the resource to close
  9. """
  10. with CancelScope() as scope:
  11. scope.cancel()
  12. await resource.aclose()