You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the server in a terminal and sending Ctrl+C, it logs:
2021-03-13 09:11:51,204 INFO: uvicorn.error -> Shutting down
2021-03-13 09:11:51,312 INFO: uvicorn.error -> Waiting for connections to close. (CTRL+C to force quit)
I had hoped to have clean shutdown using hooks to cancel active tasks and return from any SSE event handlers:
The shutdown handlers will run once all connections have been closed, and any in-process background tasks have completed.
So it is bad timing. The on_shutdown functions won't get called until the things they are trying to do are already done. What I really need is a hypothetical before_shutdown hook that gets called when starting the shutdown process. There is a feature request for that in Starlette.
When running the server in a terminal and sending Ctrl+C, it logs:
I had hoped to have clean shutdown using hooks to cancel active tasks and return from any SSE event handlers:
But per the documentation:
So it is bad timing. The
on_shutdown
functions won't get called until the things they are trying to do are already done. What I really need is a hypotheticalbefore_shutdown
hook that gets called when starting the shutdown process. There is a feature request for that in Starlette.This SO question is the same problem, but with websockets: https://stackoverflow.com/questions/58133694/graceful-shutdown-of-uvicorn-starlette-app-with-websockets
The best answer so far has monkey-patching uvicorn's signal handling, which is pragmatic but not very elegant.
The text was updated successfully, but these errors were encountered: