Is there a way to kill uvicorn cleanly?
That's because you're running uvicorn
as your only server. The uvicorn
is not a process manager and, as so, it does not manage it's workers life cycle. That's why they recommend running uvicorn using gunicorn+UvicornWorker for production.
That said, you can kill the spawned workers and trigger it's shutdown using the script below:
$ kill $(pgrep -P $uvicorn_pid)
The reason why this works but not the kill
on the parent pid is because when you ^C
something, the signal is transmitted throughout all of it's spawned processes that are attached to the stdin
.