File tree Expand file tree Collapse file tree
posthog/temporal/session_replay/surfacing_scoring_sweep Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717import os
1818import tempfile
1919import threading
20+ from typing import TYPE_CHECKING
2021from urllib .parse import urlparse
2122
2223import numpy as np
2324import pandas as pd
24- import xgboost as xgb
2525import structlog
2626
27+ if TYPE_CHECKING :
28+ import xgboost as xgb
29+
2730from posthog .storage import object_storage
2831from posthog .temporal .session_replay .surfacing_scoring_sweep .feature_schema import assert_serving_schema_parity
2932from posthog .temporal .session_replay .surfacing_scoring_sweep .features import feature_matrix
@@ -82,6 +85,11 @@ def _load_booster() -> xgb.Booster:
8285
8386 On first load: runs assert_serving_schema_parity and caches feature_names.
8487 """
88+ # Deferred: xgboost dlopens libomp at import, which can fail on machines without an OpenMP
89+ # runtime. This module is imported (via the package __init__) by the shared temporal worker,
90+ # and a scoring-only native dep must not stop every other workflow from loading.
91+ import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
92+
8593 global _BOOSTER , _FEATURE_NAMES
8694 cached_booster = _BOOSTER
8795 if cached_booster is not None :
@@ -172,6 +180,8 @@ def predict(df: pd.DataFrame) -> np.ndarray:
172180 path and skips re-validation. Returned array is positionally aligned
173181 with `df.index`.
174182 """
183+ import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
184+
175185 booster = _load_booster ()
176186 feature_names = get_feature_names ()
177187
You can’t perform that action at this time.
0 commit comments