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

Method _test_connection

asyncpg/cluster.py:508–543  ·  view source on GitHub ↗
(self, timeout=60)

Source from the content-addressed store, hash-verified

506 }
507
508 def _test_connection(self, timeout=60):
509 self._connection_addr = None
510
511 loop = asyncio.new_event_loop()
512
513 try:
514 for i in range(timeout):
515 if self._connection_addr is None:
516 conn_spec = self._get_connection_spec()
517 if conn_spec is None:
518 time.sleep(1)
519 continue
520
521 try:
522 con = loop.run_until_complete(
523 asyncpg.connect(database='postgres',
524 user='postgres',
525 timeout=5, loop=loop,
526 **self._connection_addr))
527 except (OSError, asyncio.TimeoutError,
528 asyncpg.CannotConnectNowError,
529 asyncpg.PostgresConnectionError):
530 time.sleep(1)
531 continue
532 except asyncpg.PostgresError:
533 # Any other error other than ServerNotReadyError or
534 # ConnectionError is interpreted to indicate the server is
535 # up.
536 break
537 else:
538 loop.run_until_complete(con.close())
539 break
540 finally:
541 loop.close()
542
543 return 'running'
544
545 def _run_pg_config(self, pg_config_path):
546 process = subprocess.run(

Callers 2

get_statusMethod · 0.95
startMethod · 0.95

Calls 3

_get_connection_specMethod · 0.95
connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected