Proper way to run code on startup and shutdown #1391
-
I’m trying to run some code before uvicorn starts and after all connections are closed. I have tried to follow the implementation of Starlette’s events but I can’t figure out how they work. The best implementation I can come up with is monkey patching my code to uvicorns startup and shutdown functions. A simple example of what I’m trying to do: Before serving requests run this After finishing all requests run this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
what you want is described as events in Starlette: https://www.starlette.io/events/ |
Beta Was this translation helpful? Give feedback.
-
I found a working solution, I believe this is the correct way to use lifespan events. If anyone has any improvements they would be greatly appreciated.
|
Beta Was this translation helpful? Give feedback.
I found a working solution, I believe this is the correct way to use lifespan events. If anyone has any improvements they would be greatly appreciated.