Close the database connection.
(self)
| 342 | await asyncio.to_thread(_clear_session_sync) |
| 343 | |
| 344 | def close(self) -> None: |
| 345 | """Close the database connection.""" |
| 346 | with self._lock: |
| 347 | if self._closed: |
| 348 | return |
| 349 | |
| 350 | self._closed = True |
| 351 | if self._is_memory_db: |
| 352 | if hasattr(self, "_shared_connection"): |
| 353 | self._shared_connection.close() |
| 354 | else: |
| 355 | with self._connections_lock: |
| 356 | connections = list(self._connections) |
| 357 | self._connections.clear() |
| 358 | for connection in connections: |
| 359 | connection.close() |
| 360 | if self._lock_path is not None and not self._lock_released: |
| 361 | self._release_file_lock(self._lock_path) |
| 362 | self._lock_released = True |