(self)
| 156 | self._setup_inactive_callback() |
| 157 | |
| 158 | async def acquire(self) -> PoolConnectionProxy: |
| 159 | if self._con is None or self._con.is_closed(): |
| 160 | self._con = None |
| 161 | await self.connect() |
| 162 | |
| 163 | elif self._generation != self._pool._generation: |
| 164 | # Connections have been expired, re-connect the holder. |
| 165 | self._pool._loop.create_task( |
| 166 | self._con.close(timeout=self._timeout)) |
| 167 | self._con = None |
| 168 | await self.connect() |
| 169 | |
| 170 | self._maybe_cancel_inactive_callback() |
| 171 | |
| 172 | self._proxy = proxy = PoolConnectionProxy(self, self._con) |
| 173 | |
| 174 | if self._setup is not None: |
| 175 | try: |
| 176 | await self._setup(proxy) |
| 177 | except (Exception, asyncio.CancelledError) as ex: |
| 178 | # If a user-defined `setup` function fails, we don't |
| 179 | # know if the connection is safe for re-use, hence |
| 180 | # we close it. A new connection will be created |
| 181 | # when `acquire` is called again. |
| 182 | try: |
| 183 | # Use `close()` to close the connection gracefully. |
| 184 | # An exception in `setup` isn't necessarily caused |
| 185 | # by an IO or a protocol error. close() will |
| 186 | # do the necessary cleanup via _release_on_close(). |
| 187 | await self._con.close() |
| 188 | finally: |
| 189 | raise ex |
| 190 | |
| 191 | self._in_use = self._pool._loop.create_future() |
| 192 | |
| 193 | return proxy |
| 194 | |
| 195 | async def release(self, timeout: Optional[float]) -> None: |
| 196 | if self._in_use is None: |
nothing calls this directly
no test coverage detected