| 217 | return "prefork" in pool |
| 218 | |
| 219 | def _close_database(self) -> None: |
| 220 | try: |
| 221 | connections = self._db.connections.all(initialized_only=True) |
| 222 | except TypeError: |
| 223 | # Support Django < 4.1 |
| 224 | connections = self._db.connections.all() |
| 225 | |
| 226 | is_prefork = self._is_prefork() |
| 227 | |
| 228 | for conn in connections: |
| 229 | try: |
| 230 | conn.close() |
| 231 | pool_enabled = self._settings.DATABASES.get(conn.alias, {}).get("OPTIONS", {}).get("pool") |
| 232 | if pool_enabled and is_prefork and hasattr(conn, "close_pool"): |
| 233 | with contextlib.suppress(KeyError): |
| 234 | conn.close_pool() |
| 235 | except self.interface_errors: |
| 236 | pass |
| 237 | except self.DatabaseError as exc: |
| 238 | str_exc = str(exc) |
| 239 | if 'closed' not in str_exc and 'not connected' not in str_exc: |
| 240 | raise |
| 241 | |
| 242 | def close_cache(self) -> None: |
| 243 | try: |