feat(server): print startup banner before heavy imports load#321
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
start_photomapleaves the terminal silent for ~10-30s (platform-dependent) before any status message appears. The console script maps tophotomap.backend.photomap_server:main, so Python must import that module — which pulls in FastAPI, the routers, and transitively CLIP/torch — before a single line ofmain()runs. Any banner printed insidemain()is therefore too late.Fix
Add a lightweight
photomap/backend/launch.pyshim that imports nothing heavy at module scope. It printsPhotoMapAI server initializing…immediately, then defers the expensivefrom photomap.backend.photomap_server import mainuntil inside its ownmain(). Repoint thestart_photomapconsole script atphotomap.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 throughlaunch.py. The banner prints once in the parent; each respawn still logsLoading...via the existing supervisor loop.Verification
SIGTERMthe worker to simulate an inline-update restart → supervisor respawns a fresh worker (HTTP 200 again).ruff checkpasses on the new module.Note
Changing the entry-point target regenerates the
start_photomapconsole script, so existing checkouts need apip install -e .to pick it up.🤖 Generated with Claude Code