fix(ci): lazy-import duckdb to prevent pytest hang

DuckDB spawns non-daemon background threads on import. Since
analytics.py was imported at module level (transitively by the
test suite), these threads kept the pytest process alive after
all tests completed. Moving the import into open_analytics_db()
means duckdb is only loaded when actually needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-24 04:26:22 +01:00
parent 8c03b16e61
commit d5e99eead1

View File

@@ -14,14 +14,14 @@ import os
from pathlib import Path
from typing import Any
import duckdb
_conn: duckdb.DuckDBPyConnection | None = None
_conn = None # duckdb.DuckDBPyConnection | None — lazy import
_DUCKDB_PATH = os.environ.get("SERVING_DUCKDB_PATH", "data/analytics.duckdb")
def open_analytics_db() -> None:
"""Open the DuckDB connection. Call once at app startup."""
import duckdb
global _conn
path = Path(_DUCKDB_PATH)
if not path.exists():