From: Daniele Varrazzo Date: Sat, 2 Sep 2023 20:47:20 +0000 (+0100) Subject: perf(waiting): drop unneeded wait_for in wait_conn_async if no timeout is set X-Git-Tag: pool-3.2.0~12^2~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a3caf2908d465c5a632a16d1c9c20ed32093da5;p=thirdparty%2Fpsycopg.git perf(waiting): drop unneeded wait_for in wait_conn_async if no timeout is set --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 3416633b9..deee10cba 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -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)