It is unlikely that the statements we shuffled around will fail;
however, let's do the right thing and make sure that, if they do, the
getconn/putconn pair remains matched.
in working state, replace it with a new one.
"""
conn = self.getconn(timeout=timeout)
- t0 = monotonic()
try:
+ t0 = monotonic()
with conn:
yield conn
finally:
+ self.putconn(conn)
t1 = monotonic()
self._stats[self._USAGE_MS] += int(1000.0 * (t1 - t0))
- self.putconn(conn)
def getconn(self, timeout: Optional[float] = None) -> Connection[Any]:
"""Obtain a connection from the pool.
self, timeout: Optional[float] = None
) -> AsyncIterator[AsyncConnection[Any]]:
conn = await self.getconn(timeout=timeout)
- t0 = monotonic()
try:
+ t0 = monotonic()
async with conn:
yield conn
finally:
+ await self.putconn(conn)
t1 = monotonic()
self._stats[self._USAGE_MS] += int(1000.0 * (t1 - t0))
- await self.putconn(conn)
async def getconn(self, timeout: Optional[float] = None) -> AsyncConnection[Any]:
logger.info("connection requested from %r", self.name)