Skip to content

Future of on_startup/on_shutdown and lifespan #2067

Answered by tiangolo
adriangb asked this question in Ideas
Discussion options

You must be logged in to vote

Funny story... 😬 It's quite a contradiction from my side, but anyway, here it goes.

  • I currently don't have support for lifespan functions in FastAPI, but I should (there might even be a PR for that). I do have startup and shutdown.
  • I agree it makes sense to remove on_startup and on_shutdown. And replace that with a single lifespan context manager/function with yield. 😬

Then, the next steps would be that I would have to patch on_startup and on_shutdown in FastAPI for backwards compatibility for a while, add support for lifespan, document it, recommend it, discourage using on_startup and on_shutdown and direct people to lifespan. And I think all that should be done, and I agree with remov…

Replies: 7 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

Kludex
Mar 6, 2023
Maintainer Sponsor

You must be logged in to vote
0 replies
Comment options

tiangolo
Mar 6, 2023
Collaborator Sponsor

You must be logged in to vote
1 reply
@adriangb
Comment options

adriangb Mar 9, 2023
Collaborator Author

Answer selected by adriangb
Comment options

Kludex
Mar 6, 2023
Maintainer Sponsor

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@sm-Fifteen
Comment options

@adriangb
Comment options

adriangb Mar 6, 2023
Collaborator Author

@sm-Fifteen
Comment options

@adriangb
Comment options

adriangb Mar 9, 2023
Collaborator Author

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
6 participants
Converted from issue

This discussion was converted from issue #2066 on March 05, 2023 21:27.