MCPcopy
hub / github.com/MagicStack/asyncpg / _acquire

Method _acquire

asyncpg/pool.py:877–899  ·  view source on GitHub ↗
(self, timeout)

Source from the content-addressed store, hash-verified

875 return PoolAcquireContext(self, timeout)
876
877 async def _acquire(self, timeout):
878 async def _acquire_impl():
879 ch = await self._queue.get() # type: PoolConnectionHolder
880 try:
881 proxy = await ch.acquire() # type: PoolConnectionProxy
882 except (Exception, asyncio.CancelledError):
883 self._queue.put_nowait(ch)
884 raise
885 else:
886 # Record the timeout, as we will apply it by default
887 # in release().
888 ch._timeout = timeout
889 return proxy
890
891 if self._closing:
892 raise exceptions.InterfaceError('pool is closing')
893 self._check_init()
894
895 if timeout is None:
896 return await _acquire_impl()
897 else:
898 return await compat.wait_for(
899 _acquire_impl(), timeout=timeout)
900
901 async def release(self, connection, *, timeout=None):
902 """Release a database connection back to the pool.

Callers 2

__aenter__Method · 0.80
__await__Method · 0.80

Calls 1

_check_initMethod · 0.95

Tested by

no test coverage detected