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

Class PoolAcquireContext

asyncpg/pool.py:1043–1072  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1041
1042
1043class PoolAcquireContext:
1044
1045 __slots__ = ('timeout', 'connection', 'done', 'pool')
1046
1047 def __init__(self, pool: Pool, timeout: Optional[float]) -> None:
1048 self.pool = pool
1049 self.timeout = timeout
1050 self.connection = None
1051 self.done = False
1052
1053 async def __aenter__(self):
1054 if self.connection is not None or self.done:
1055 raise exceptions.InterfaceError('a connection is already acquired')
1056 self.connection = await self.pool._acquire(self.timeout)
1057 return self.connection
1058
1059 async def __aexit__(
1060 self,
1061 exc_type: Optional[Type[BaseException]] = None,
1062 exc_val: Optional[BaseException] = None,
1063 exc_tb: Optional[TracebackType] = None,
1064 ) -> None:
1065 self.done = True
1066 con = self.connection
1067 self.connection = None
1068 await self.pool.release(con)
1069
1070 def __await__(self):
1071 self.done = True
1072 return self.pool._acquire(self.timeout).__await__()
1073
1074
1075def create_pool(dsn=None, *,

Callers 1

acquireMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…