-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Shutting down the uvicorn server master from a FastAPI worker #1509
Description
First check
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
Description
I want to kill the entire uvicorn server whenever one of my workers encounters an issue it cannot resolve.
I currently run fastapi inside the bundled Docker container recommended in the documentation, when my worker cannot connect to an upstream api because it is down/unavailable, I can call sys.quit(-1) to kill the worker with an error code, but this only causes uvicorn to restart the worker.
Is there any interface to kill the uvicorn master server and return an error code so that it kills my Docker container? The only alternative I can see is using health checks instead of killing the container
One solution I have found would be using os.kill to kill pid 1/sending a SIGTERM but I'm not sure if ASGI may have a procedure/interface for this rather than bluntly signalling the process. I have searched the uvicorn and Starlette docs and found nothing
