MCPcopy
hub / github.com/psycopg/psycopg / wait

Method wait

psycopg_pool/psycopg_pool/pool_async.py:955–974  ·  view source on GitHub ↗

Wait for a connection to be set and return it. Raise an exception if the wait times out or if fail() is called.

(self, timeout: float)

Source from the content-addressed store, hash-verified

953 self._cond = ACondition()
954
955 async def wait(self, timeout: float) -> ACT:
956 """Wait for a connection to be set and return it.
957
958 Raise an exception if the wait times out or if fail() is called.
959 """
960 async with self._cond:
961 if not (self.conn or self.error):
962 try:
963 if not await self._cond.wait_timeout(timeout):
964 self.error = PoolTimeout(
965 f"couldn't get a connection after {timeout:.2f} sec"
966 )
967 except CLIENT_EXCEPTIONS as ex:
968 self.error = ex
969
970 if self.error:
971 raise self.error
972 else:
973 assert self.conn
974 return self.conn
975
976 async def set(self, conn: ACT) -> bool:
977 """Signal the client waiting that a connection is ready.

Callers 1

_getconn_uncheckedMethod · 0.95

Calls 2

PoolTimeoutClass · 0.85
wait_timeoutMethod · 0.45

Tested by

no test coverage detected