Migrate FastAPI on_event handlers to lifespan#2369
Open
FawwadAhmed11 wants to merge 1 commit into
Open
Conversation
FastAPI deprecated on_event in 0.109; the upper pin <0.116 was defensive against possible removal. Replace the three on_event handlers with a single asynccontextmanager-based lifespan and a startup_hook extension point overridden by ParallelHttpInterface. Drop the FastAPI upper bound. Closes roboflow#1960
|
Hamza Ahmed seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
2 tasks
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.
FastAPI deprecated
on_eventin 0.109; the upper pin<0.116was added defensively in case it was removed. It hasn't been removed through 0.128+, but the pin still blocks users who need a newer FastAPI. This PR migrates offon_eventand drops the pin.Closes #1960
What does this PR do?
Replaces the three
on_eventhandlers inhttp_api.pyandparallel_http_api.pywith a singleasynccontextmanager-basedlifespanfunction. Adds anasync startup_hook()extension point onHttpInterfacethatParallelHttpInterfaceoverrides for its Redis-dispatch setup. Drops thefastapi<0.116upper bound fromrequirements/_requirements.txt.All existing behavior is preserved: shutdown telemetry flush, preload model thread launch (still gated on
PRELOAD_MODELS/PINNED_MODELS), and parallel Redis checker thread setup all work identically — just triggered bylifespaninstead ofon_event.Related Issue(s): Fixes #1960
Type of Change
Testing
Test details:
python -m py_compilepasses on both modified Python files (syntax and closure validity confirmed)make check_code_qualitypasses clean — black, isort, flake8 all greenChecklist
Additional Context
The
lifespanfunction is defined insideHttpInterface.__init__so it can close over local variables (description,should_preload,model_init_state,initialize_models) that are needed at startup/shutdown time. Python resolves these at call time, not definition time, so there is noNameErrorrisk even though some variables are defined later in__init__.