MCPcopy
hub / github.com/psycopg/psycopg / check

Method check

psycopg_pool/psycopg_pool/pool.py:513–546  ·  view source on GitHub ↗

Verify the state of the connections currently in the pool. Test each connection: if it works return it to the pool, otherwise dispose of it and create a new one.

(self)

Source from the content-addressed store, hash-verified

511 self.run_task(AddConnection(self))
512
513 def check(self) -> None:
514 """Verify the state of the connections currently in the pool.
515
516 Test each connection: if it works return it to the pool, otherwise
517 dispose of it and create a new one.
518 """
519 with self._lock:
520 conns = list(self._pool)
521 self._pool.clear()
522
523 # Give a chance to the pool to grow if it has no connection.
524 # In case there are enough connection, or the pool is already
525 # growing, this is a no-op.
526 self._maybe_grow_pool()
527
528 while conns:
529 conn = conns.pop()
530
531 # Check for expired connections
532 if conn._expire_at <= monotonic():
533 logger.info("discarding expired connection %s", conn)
534 self._close_connection(conn)
535 self.run_task(AddConnection(self))
536 continue
537
538 # Check for broken connections
539 try:
540 self.check_connection(conn)
541 except CLIENT_EXCEPTIONS:
542 self._stats[self._CONNECTIONS_LOST] += 1
543 logger.warning("discarding broken connection: %s", conn)
544 self.run_task(AddConnection(self))
545 else:
546 self._add_to_pool(conn)
547
548 @staticmethod
549 def check_connection(conn: CT) -> None:

Callers 12

test_refill_on_checkFunction · 0.45
test_checkFunction · 0.45
test_check_idleFunction · 0.45
test_check_max_lifetimeFunction · 0.45
test_stats_connectFunction · 0.45
test_checkFunction · 0.45
test_checkFunction · 0.45
test_refill_on_checkFunction · 0.45
test_checkFunction · 0.45
test_check_idleFunction · 0.45
test_check_max_lifetimeFunction · 0.45
test_stats_connectFunction · 0.45

Calls 8

_maybe_grow_poolMethod · 0.95
_close_connectionMethod · 0.95
run_taskMethod · 0.95
check_connectionMethod · 0.95
_add_to_poolMethod · 0.95
AddConnectionClass · 0.70
clearMethod · 0.45
infoMethod · 0.45

Tested by 12

test_refill_on_checkFunction · 0.36
test_checkFunction · 0.36
test_check_idleFunction · 0.36
test_check_max_lifetimeFunction · 0.36
test_stats_connectFunction · 0.36
test_checkFunction · 0.36
test_checkFunction · 0.36
test_refill_on_checkFunction · 0.36
test_checkFunction · 0.36
test_check_idleFunction · 0.36
test_check_max_lifetimeFunction · 0.36
test_stats_connectFunction · 0.36