(self)
| 3412 | ) |
| 3413 | |
| 3414 | def reset(self): |
| 3415 | # Create and fill up a thread safe queue with ``None`` values. |
| 3416 | try: |
| 3417 | if self._in_maintenance: |
| 3418 | self._lock.acquire() |
| 3419 | self._locked = True |
| 3420 | |
| 3421 | # Record metrics for connections being removed before clearing |
| 3422 | # Note: Access pool.queue directly to avoid deadlock since we may |
| 3423 | # already hold self._lock (which is non-reentrant) |
| 3424 | if ( |
| 3425 | hasattr(self, "_connections") |
| 3426 | and self._connections |
| 3427 | and hasattr(self, "pool") |
| 3428 | ): |
| 3429 | with self._lock: |
| 3430 | connections_in_queue = {conn for conn in self.pool.queue if conn} |
| 3431 | idle_count = len(connections_in_queue) |
| 3432 | in_use_count = len(self._connections) - idle_count |
| 3433 | if idle_count > 0 or in_use_count > 0: |
| 3434 | pool_name = get_pool_name(self) |
| 3435 | if idle_count > 0: |
| 3436 | record_connection_count( |
| 3437 | pool_name=pool_name, |
| 3438 | connection_state=ConnectionState.IDLE, |
| 3439 | counter=-idle_count, |
| 3440 | ) |
| 3441 | if in_use_count > 0: |
| 3442 | record_connection_count( |
| 3443 | pool_name=pool_name, |
| 3444 | connection_state=ConnectionState.USED, |
| 3445 | counter=-in_use_count, |
| 3446 | ) |
| 3447 | |
| 3448 | self.pool = self.queue_class(self.max_connections) |
| 3449 | while True: |
| 3450 | try: |
| 3451 | self.pool.put_nowait(None) |
| 3452 | except Full: |
| 3453 | break |
| 3454 | |
| 3455 | # Keep a list of actual connection instances so that we can |
| 3456 | # disconnect them later. |
| 3457 | self._connections = [] |
| 3458 | finally: |
| 3459 | if self._locked: |
| 3460 | try: |
| 3461 | self._lock.release() |
| 3462 | except Exception: |
| 3463 | pass |
| 3464 | self._locked = False |
| 3465 | |
| 3466 | # this must be the last operation in this method. while reset() is |
| 3467 | # called when holding _fork_lock, other threads in this process |
| 3468 | # can call _checkpid() which compares self.pid and os.getpid() without |
| 3469 | # holding any lock (for performance reasons). keeping this assignment |
| 3470 | # as the last operation ensures that those other threads will also |
| 3471 | # notice a pid difference and block waiting for the first thread to |
nothing calls this directly
no test coverage detected