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

Method _acquire

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

Source from the content-addressed store, hash-verified

992 return PoolAcquireContext(self, timeout)
993
994 async def _acquire(self, timeout):
995 async def _acquire_impl():
996 ch = await self._queue.get() # type: PoolConnectionHolder
997 try:
998 proxy = await ch.acquire() # type: PoolConnectionProxy
999 except (Exception, asyncio.CancelledError):
1000 self._queue.put_nowait(ch)
1001 self._schedule_min_size_maintenance()
1002 raise
1003 else:
1004 # Record the timeout, as we will apply it by default
1005 # in release().
1006 ch._timeout = timeout
1007 return proxy
1008
1009 if self._closing:
1010 raise exceptions.InterfaceError('pool is closing')
1011 self._check_init()
1012
1013 if timeout is None:
1014 return await _acquire_impl()
1015 else:
1016 return await compat.wait_for(
1017 _acquire_impl(), timeout=timeout)
1018
1019 async def release(self, connection, *, timeout=None):
1020 """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