Replace deprecated @app.on_event with lifespan context manager#389
Open
hobostay wants to merge 1 commit intomicrosoft:mainfrom
Open
Replace deprecated @app.on_event with lifespan context manager#389hobostay wants to merge 1 commit intomicrosoft:mainfrom
hobostay wants to merge 1 commit intomicrosoft:mainfrom
Conversation
FastAPI deprecated @app.on_event("startup") since version 0.103.0
and it will be removed in a future release. Replace with the
recommended lifespan context manager pattern.
This also prevents potential issues with auto-reload loading the
model multiple times into GPU memory.
Co-Authored-By: Claude Opus 4.7 <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.
Summary
@app.on_event("startup")with the recommendedlifespancontext manager pattern indemo/web/app.py@app.on_event("startup")is deprecated since FastAPI 0.103.0 and will be removed in a future versionDetails
Affected file:
demo/web/app.py(lines 335-356)The deprecated
on_event("startup")pattern has known issues with auto-reload where the startup event may fire multiple times, loading multiple copies of the large model into GPU memory and causing OOM. The lifespan context manager is the recommended replacement.Test plan
MODEL_PATHset and verify it loads correctly🤖 Generated with Claude Code