Skip to content

feat(server): print startup banner before heavy imports load#321

Merged
lstein merged 1 commit into
masterfrom
lstein/feature/startup-banner
Jun 9, 2026
Merged

feat(server): print startup banner before heavy imports load#321
lstein merged 1 commit into
masterfrom
lstein/feature/startup-banner

Conversation

@lstein

@lstein lstein commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Problem

Running start_photomap leaves the terminal silent for ~10-30s (platform-dependent) before any status message appears. The console script maps to photomap.backend.photomap_server:main, so Python must import that module — which pulls in FastAPI, the routers, and transitively CLIP/torch — before a single line of main() runs. Any banner printed inside main() is therefore too late.

Fix

Add a lightweight photomap/backend/launch.py shim that imports nothing heavy at module scope. It prints PhotoMapAI server initializing… immediately, then defers the expensive from photomap.backend.photomap_server import main until inside its own main(). Repoint the start_photomap console script at photomap.backend.launch:main.

Relaunch loop / inline-update safety

The supervisor relaunch loop and the inline-update restart are unaffected: they respawn workers via python -m photomap.backend.photomap_server … --once, which never goes through launch.py. The banner prints once in the parent; each respawn still logs Loading... via the existing supervisor loop.

Verification

  • Banner appears within ~1s, before the heavy import completes.
  • End-to-end: supervisor spawns a worker (HTTP 200) → SIGTERM the worker to simulate an inline-update restart → supervisor respawns a fresh worker (HTTP 200 again).
  • ruff check passes on the new module.

Note

Changing the entry-point target regenerates the start_photomap console script, so existing checkouts need a pip install -e . to pick it up.

🤖 Generated with Claude Code

start_photomap pointed at photomap_server:main, so the console script had
to import that module (FastAPI, routers, CLIP/torch) before any line of
main() ran — leaving the terminal silent for 10-30s. Add a lightweight
launch.py shim that imports nothing heavy at module scope, prints
"PhotoMapAI server initializing…", then defers the expensive import.

The supervisor relaunch loop and inline-update restart are unaffected:
they respawn workers via `python -m photomap.backend.photomap_server`,
which never goes through launch.py.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lstein lstein merged commit c7239a6 into master Jun 9, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant