Clean up connection pool and record metrics when garbage collected.
(self)
| 3047 | self.pid = os.getpid() |
| 3048 | |
| 3049 | def __del__(self) -> None: |
| 3050 | """Clean up connection pool and record metrics when garbage collected.""" |
| 3051 | try: |
| 3052 | if not hasattr(self, "_available_connections") or not hasattr( |
| 3053 | self, "_in_use_connections" |
| 3054 | ): |
| 3055 | return |
| 3056 | # Record metrics for all connections being removed |
| 3057 | idle_count = len(self._available_connections) |
| 3058 | in_use_count = len(self._in_use_connections) |
| 3059 | if idle_count > 0 or in_use_count > 0: |
| 3060 | pool_name = get_pool_name(self) |
| 3061 | if idle_count > 0: |
| 3062 | record_connection_count( |
| 3063 | pool_name=pool_name, |
| 3064 | connection_state=ConnectionState.IDLE, |
| 3065 | counter=-idle_count, |
| 3066 | ) |
| 3067 | if in_use_count > 0: |
| 3068 | record_connection_count( |
| 3069 | pool_name=pool_name, |
| 3070 | connection_state=ConnectionState.USED, |
| 3071 | counter=-in_use_count, |
| 3072 | ) |
| 3073 | except Exception: |
| 3074 | pass |
| 3075 | |
| 3076 | def _checkpid(self) -> None: |
| 3077 | # _checkpid() attempts to keep ConnectionPool fork-safe on modern |
nothing calls this directly
no test coverage detected