diff --git a/src/second_brain/embeddings/__init__.py b/src/second_brain/embeddings/__init__.py index 61b43b9..c11ea5d 100644 --- a/src/second_brain/embeddings/__init__.py +++ b/src/second_brain/embeddings/__init__.py @@ -23,6 +23,7 @@ index, not authoritative state. from __future__ import annotations +import atexit import logging import os from typing import Any @@ -73,6 +74,11 @@ def _get_pool() -> ConnectionPool | None: if not dsn: return None _pool = ConnectionPool(dsn, min_size=1, max_size=4, open=True, timeout=10) + # Make sure the pool's worker threads get a clean shutdown when the + # interpreter exits; without this psycopg_pool prints + # "couldn't stop thread pool-1-worker-N within 5.0 seconds" on every + # `second-brain process` run. + atexit.register(close_pool) return _pool