Improve lifespan control #2582
Unanswered
skeletorXVI
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposal
Provide means to better control the application lifetime.
e.g. provide exception classes similar to
SystemExit
to allow apps more control over their own lifetime.Background
I'm currently working on a small project using FastAPI, during the startup process I run some checks and if they are not fulfilled the startup has to fail.
While it is possible to just raise an exception this actually results in a huge unwanted traceback, when this is the expected behavior and I just need
Startup procedure failed, xyz not fulfilled
.I have solved this now by handling a special exception class in the
Router.lifespan
method by patching it on theRouter
instance created used by theFastAPI
instance.While this solution works for me, I believe this functionality should be build into Starlette.
My solution
Beta Was this translation helpful? Give feedback.
All reactions