| """ | |
| startup_progress.py — Shared state for startup benchmark progress. | |
| Used by web.py (writer) and startup.py (reader) to show live progress | |
| on the loading page while models are being tested. | |
| """ | |
| import threading | |
| _lock = threading.Lock() | |
| # Current phase: "init", "benchmark", "ready" | |
| phase: str = "init" | |
| total: int = 0 | |
| # model -> {"status": "testing"|"ok"|"fail", "detail": str} | |
| _models: dict[str, dict] = {} | |
| def update(model: str, status: str, detail: str = ""): | |
| """Record a model's benchmark status. Thread-safe.""" | |
| with _lock: | |
| _models[model] = {"status": status, "detail": detail} | |
| def snapshot() -> dict: | |
| """Return current progress snapshot for the loading page.""" | |
| with _lock: | |
| return { | |
| "phase": phase, | |
| "total": total, | |
| "models": dict(_models), | |
| } | |