Skip to content

Commit 55965e7

Browse files
committed
chore: add debug logging at connection time
Only added to the Python implementation for the moment. See #888
1 parent 9266dc2 commit 55965e7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

psycopg/psycopg/generators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]:
6565
"""
6666
deadline = monotonic() + timeout if timeout else 0.0
6767

68+
# To debug slowdown during connection:
69+
#
70+
# $ PSYCOPG_IMPL=python python
71+
# >>> import logging
72+
# >>> logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')
73+
6874
conn = pq.PGconn.connect_start(conninfo.encode())
75+
logger.debug("connection started: %s", conn)
6976
while True:
7077
if conn.status == BAD:
7178
encoding = conninfo_encoding(conninfo)
@@ -74,6 +81,7 @@ def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]:
7481
)
7582

7683
status = conn.connect_poll()
84+
logger.debug("connection polled: %s", conn)
7785

7886
if status == POLL_READING or status == POLL_WRITING:
7987
wait = WAIT_R if status == POLL_READING else WAIT_W

0 commit comments

Comments
 (0)