From: Dylan Young Date: Mon, 15 Jun 2026 03:16:00 +0000 (-0300) Subject: fix: wait_selector KeyError X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9f196895eb6d3973437102fb50802266dedafea;p=thirdparty%2Fpsycopg.git fix: wait_selector KeyError --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 6a6efab09..3ce7f20c8 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -72,7 +72,7 @@ def wait_selector(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV: try: s = next(gen) with DefaultSelector() as sel: - sel.register(fileno, s) + sel.register(fileno, (last_s := s)) while True: if not (rlist := sel.select(timeout=interval)): # Check if it was a timeout or we were disconnected @@ -82,7 +82,9 @@ def wait_selector(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV: ready = rlist[0][1] s = gen.send(ready) - sel.register(fileno, s) + if last_s != s: + sel.unregister(fileno) + sel.register(fileno, (last_s := s)) except StopIteration as ex: rv: RV = ex.value