MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _cancel

Method _cancel

asyncpg/connection.py:1678–1709  ·  view source on GitHub ↗
(self, waiter, cancel_waiter=None)

Source from the content-addressed store, hash-verified

1676 await self._protocol.close_statement(stmt, protocol.NO_TIMEOUT)
1677
1678 async def _cancel(self, waiter, cancel_waiter=None):
1679 try:
1680 async with compat.timeout(self._config.command_timeout):
1681 try:
1682 await connect_utils._cancel(
1683 loop=self._loop, addr=self._addr, params=self._params,
1684 backend_pid=self._protocol.backend_pid,
1685 backend_secret=self._protocol.backend_secret)
1686 except ConnectionResetError:
1687 # Some servers reset the auxiliary connection after
1688 # receiving the CancelRequest. The original connection
1689 # still has to acknowledge the cancelled query.
1690 pass
1691
1692 if not waiter.done():
1693 waiter.set_result(None)
1694 if cancel_waiter is not None:
1695 await asyncio.shield(cancel_waiter)
1696 except asyncio.CancelledError:
1697 # Teardown can cancel this background task. Its waiters are
1698 # completed in finally, without leaking CancelledError.
1699 pass
1700 except Exception:
1701 if not self._aborted:
1702 # A failed CancelRequest leaves the original connection's
1703 # protocol state uncertain. It cannot be reused safely.
1704 self.terminate()
1705 finally:
1706 self._cancellations.discard(
1707 asyncio.current_task(self._loop))
1708 if not waiter.done():
1709 waiter.set_result(None)
1710
1711 def _cancel_current_command(self, waiter, cancel_waiter=None):
1712 self._cancellations.add(self._loop.create_task(

Callers 1

Calls 1

terminateMethod · 0.95

Tested by

no test coverage detected