MCPcopy
hub / github.com/psycopg/psycopg / _getconn_with_check_loop

Method _getconn_with_check_loop

psycopg_pool/psycopg_pool/pool.py:222–246  ·  view source on GitHub ↗
(self, deadline: float)

Source from the content-addressed store, hash-verified

220 ) from None
221
222 def _getconn_with_check_loop(self, deadline: float) -> CT:
223 attempt: AttemptWithBackoff | None = None
224
225 while True:
226 conn = self._getconn_unchecked(deadline - monotonic())
227 try:
228 self._check_connection(conn)
229 except CLIENT_EXCEPTIONS:
230 self._putconn(conn, from_getconn=True)
231 else:
232 logger.info("connection given by %r", self.name)
233 return conn
234
235 # Delay further checks to avoid a busy loop, using the same
236 # backoff policy used in reconnection attempts.
237 now = monotonic()
238 if not attempt:
239 attempt = AttemptWithBackoff(timeout=deadline - now)
240 else:
241 attempt.update_delay(now)
242
243 if attempt.time_to_give_up(now):
244 raise PoolTimeout()
245 else:
246 sleep(attempt.delay)
247
248 def _getconn_unchecked(self, timeout: float) -> CT:
249 # Critical section: decide here if there's a connection ready

Callers 1

getconnMethod · 0.95

Calls 8

_getconn_uncheckedMethod · 0.95
_check_connectionMethod · 0.95
_putconnMethod · 0.95
update_delayMethod · 0.95
time_to_give_upMethod · 0.95
AttemptWithBackoffClass · 0.85
PoolTimeoutClass · 0.85
infoMethod · 0.45

Tested by

no test coverage detected