-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add support for fastapi lifespan events #110
Comments
Hi! thanks for your contribution!, great first issue! |
hi @robTheBuildr, we are using the FastAPI lifespan to manage our parallel inference workers. May I know more about your use case and what you are trying to achieve with lifespan? |
@robTheBuildr what will be helpful is a reproducible code snippet we can run that shows something you are trying to do, but not able to do with litserve |
@williamFalcon @aniketmaurya Hi! I'm new to the project and this seems interesting to our team for the use-cases we are working on.
In our case, we would essentially like to be able to add custom middleware to the FastAPI object so that we can track internal metrics and other things that is necessary for our infra. An example of how that would look like is this:
I'm not sure if it's possible to also allow users to pass in their own FastAPI app that has it's own lifespan and then append a lifespan that the LitServer uses to it. |
🚀 Feature
Add the ability for developers to customize the FastAPI
lifespan
,startup
, and 'shutdown` event handlers.Motivation
Users can use this to setup logging or resource management.
Pitch
There are 2 options here.
Add a function
attach_event_handler(event: str, func: Callable)
which takes either 'lifespan', 'startup' or 'shutdown' as the event and applies the given logic.More explicit and abstracting away FastAPI Lifespan event knowledge from the user, add
during_lifespan(func: Callable)
,on_startup(func: Callable)
, andon_shutdown(func: Callable)
that the user can call on Server to apply these lifespan handlers.Alternatives
Add custom template startup and shutdown event handler for logging and resource management. This will get cumbersome.
Additional context
The text was updated successfully, but these errors were encountered: