The key libraries to achieve graceful shutting down to a Uvicorn server running a FastAPI application are the built in os and signal modules.
Given an endpoint with which a client can request the server to shutdown.
os.kill(os.getpid(), signal.SIGTERM)os.getpid() retrieves the running process' system ID and then signal.SIGINT is passed to the process to signal an interrupt.