]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
perf(waiting): drop unneeded wait_for in wait_conn_async if no timeout is set
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Sep 2023 20:47:20 +0000 (21:47 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 11 Oct 2023 21:45:38 +0000 (23:45 +0200)
psycopg/psycopg/waiting.py

index 3416633b9190adf0f92079dee1a8fe76ac5e038a..deee10cba3bbd922678f72b80239580c1e0600e6 100644 (file)
@@ -106,6 +106,8 @@ async def wait_async(
     :param gen: a generator performing database operations and yielding
         `Ready` values when it would block.
     :param fileno: the file descriptor to wait on.
+    :param timeout: timeout (in seconds) to check for other interrupt, e.g.
+        to allow Ctrl-C. If zero or None, wait indefinitely.
     :return: whatever `!gen` returns on completion.
 
     Behave like in `wait()`, but exposing an `asyncio` interface.
@@ -182,8 +184,6 @@ async def wait_conn_async(gen: PQGenConn[RV], timeout: Optional[float] = None) -
 
     try:
         fileno, s = next(gen)
-        if not timeout:
-            timeout = None
         while True:
             reader = s & WAIT_R
             writer = s & WAIT_W
@@ -196,7 +196,10 @@ async def wait_conn_async(gen: PQGenConn[RV], timeout: Optional[float] = None) -
             if writer:
                 loop.add_writer(fileno, wakeup, READY_W)
             try:
-                await wait_for(ev.wait(), timeout)
+                if timeout:
+                    await wait_for(ev.wait(), timeout)
+                else:
+                    await ev.wait()
             finally:
                 if reader:
                     loop.remove_reader(fileno)