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

Method wait

psycopg_pool/psycopg_pool/pool.py:139–169  ·  view source on GitHub ↗

Wait for the pool to be full (with `min_size` connections) after creation. Close the pool, and raise `PoolTimeout`, if not ready within *timeout* sec. Calling this method is not mandatory: you can try and use the pool immediately after its creation. The fir

(self, timeout: float = 30.0)

Source from the content-addressed store, hash-verified

137 )
138
139 def wait(self, timeout: float = 30.0) -> None:
140 """
141 Wait for the pool to be full (with `min_size` connections) after creation.
142
143 Close the pool, and raise `PoolTimeout`, if not ready within *timeout*
144 sec.
145
146 Calling this method is not mandatory: you can try and use the pool
147 immediately after its creation. The first client will be served as soon
148 as a connection is ready. You can use this method if you prefer your
149 program to terminate in case the environment is not configured
150 properly, rather than trying to stay up the hardest it can.
151 """
152 self._check_open_getconn()
153
154 with self._lock:
155 assert not self._pool_full_event
156 if len(self._pool) >= self._min_size:
157 return
158 self._pool_full_event = Event()
159
160 logger.info("waiting for pool %r initialization", self.name)
161 if not self._pool_full_event.wait(timeout):
162 self.close() # stop all the tasks
163 raise PoolTimeout(f"pool initialization incomplete after {timeout} sec")
164
165 with self._lock:
166 assert self._pool_full_event
167 self._pool_full_event = None
168
169 logger.info("pool %r is ready to use", self.name)
170
171 @contextmanager
172 def connection(self, timeout: float | None = None) -> Iterator[CT]:

Callers 4

openMethod · 0.95
test_del_no_warningFunction · 0.95

Calls 5

_check_open_getconnMethod · 0.95
closeMethod · 0.95
PoolTimeoutClass · 0.85
infoMethod · 0.45
waitMethod · 0.45

Tested by 3

test_del_no_warningFunction · 0.76