psycopg.git / summary / log / commit / refs
commit 19e148abcbfa4e95e01e819f4de35e6944581e6a
Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date: Fri Oct 09 08:05:20 2026 +0000
refactor: rewrite wait loop on connect in a more compact way
psycopg/psycopg/generators.py | 6 ++----
psycopg_c/psycopg_c/_psycopg/generators.pyx | 8 +++-----
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/psycopg/psycopg/generators.py b/psycopg/psycopg/generators.py
index b51690dc..81a84021 100644
--- a/psycopg/psycopg/generators.py
+++ b/psycopg/psycopg/generators.py
@@ -83,10 +83,8 @@ def _connect(conninfo: str) -> PQGenConn[PGconn]:
if status == POLL_READING or status == POLL_WRITING:
wait = WAIT_R if status == POLL_READING else WAIT_W
- while True:
- ready = yield conn.socket, wait
- if ready:
- break
+ while not (yield conn.socket, wait):
+ pass
elif status == POLL_OK:
break
diff --git a/psycopg_c/psycopg_c/_psycopg/generators.pyx b/psycopg_c/psycopg_c/_psycopg/generators.pyx
index 5a36f2b9..b1191ad0 100644
--- a/psycopg_c/psycopg_c/_psycopg/generators.pyx
+++ b/psycopg_c/psycopg_c/_psycopg/generators.pyx
@@ -35,7 +35,7 @@ def connect(conninfo: str) -> PQGenConn[abc.PGconn]:
cdef libpq.PGconn *pgconn_ptr = conn._pgconn_ptr
cdef int conn_status = libpq.PQstatus(pgconn_ptr)
cdef int poll_status
- cdef object wait, ready
+ cdef object wait
logger.debug("connection started: %s", conn)
while True:
@@ -55,10 +55,8 @@ def connect(conninfo: str) -> PQGenConn[abc.PGconn]:
or poll_status == libpq.PGRES_POLLING_WRITING
):
wait = WAIT_R if poll_status == libpq.PGRES_POLLING_READING else WAIT_W
- while True:
- ready = yield (libpq.PQsocket(pgconn_ptr), wait)
- if ready:
- break
+ while not (yield (libpq.PQsocket(pgconn_ptr), wait)):
+ pass
elif poll_status == libpq.PGRES_POLLING_OK:
break
[parent: 438d8402d25e]