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)
| 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]: |