From: Daniele Varrazzo Date: Sat, 13 Feb 2021 22:42:00 +0000 (+0100) Subject: Awake the pool client outside the critical section X-Git-Tag: 3.0.dev0~87^2~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24cbbe5472d9d68de4ae8fd3a3849134804ab9a8;p=thirdparty%2Fpsycopg.git Awake the pool client outside the critical section --- diff --git a/psycopg3/psycopg3/pool.py b/psycopg3/psycopg3/pool.py index 358203ec5..b4a9eaf17 100644 --- a/psycopg3/psycopg3/pool.py +++ b/psycopg3/psycopg3/pool.py @@ -148,14 +148,18 @@ class ConnectionPool: # Critical section: if there is a client waiting give it the connection # otherwise put it back into the pool. with self._lock: + pos: Optional[WaitingClient] = None if self._waiting: - # Give the connection to the client and notify it + # Extract the first client from the queue pos = self._waiting.popleft() - pos.set(conn) else: - # No client waiting for a connection: put it back into the queue + # No client waiting for a connection: put it back into the pool self._pool.append(conn) + # If we found a client in queue, give it the connection and notify it + if pos: + pos.set(conn) + def _reset_transaction_status(self, conn: Connection) -> None: """ Bring a connection to IDLE state or close it.