MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / _connection_addr_from_pidfile

Method _connection_addr_from_pidfile

asyncpg/cluster.py:462–506  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

460 self._pg_version = self._get_pg_version()
461
462 def _connection_addr_from_pidfile(self):
463 pidfile = os.path.join(self._data_dir, 'postmaster.pid')
464
465 try:
466 with open(pidfile, 'rt') as f:
467 piddata = f.read()
468 except FileNotFoundError:
469 return None
470
471 lines = piddata.splitlines()
472
473 if len(lines) < 6:
474 # A complete postgres pidfile is at least 6 lines
475 return None
476
477 pmpid = int(lines[0])
478 if self._daemon_pid and pmpid != self._daemon_pid:
479 # This might be an old pidfile left from previous postgres
480 # daemon run.
481 return None
482
483 portnum = lines[3]
484 sockdir = lines[4]
485 hostaddr = lines[5]
486
487 if sockdir:
488 if sockdir[0] != '/':
489 # Relative sockdir
490 sockdir = os.path.normpath(
491 os.path.join(self._data_dir, sockdir))
492 host_str = sockdir
493 else:
494 host_str = hostaddr
495
496 if host_str == '*':
497 host_str = 'localhost'
498 elif host_str == '0.0.0.0':
499 host_str = '127.0.0.1'
500 elif host_str == '::':
501 host_str = '::1'
502
503 return {
504 'host': host_str,
505 'port': portnum
506 }
507
508 def _test_connection(self, timeout=60):
509 self._connection_addr = None

Callers 1

_get_connection_specMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected