Reputation: 31
I have developed a FastAPI Web Application.
If I run the server and it is down or crashed for some reason. I need multiple instances of server to be running.
I currently run the server with the following code.
if __name__ == '__main__':
uvicorn.run("__main__:app", host="0.0.0.0", port=5000,reload=True, workers=4)
What is the role of workers here? If it is running the server on 4 different processors. does that mean it has 4 instances of running the server ?
when I run the server with workers. I cant stop the server. I need to kill the server with PId. Is there a better way to stop it?
if that's not like creating instances. How can we achieve it with FastAPI.
Upvotes: 1
Views: 4678
Reputation: 522
notice: you can not run workers in reload=True
if __name__ == '__main__':
uvicorn.run("main:app", host="0.0.0.0", port=5000, workers=4)
there is two way to stop it 1.terminate 2.kill pid(kill $(pgrep -P $uvicorn_pid))
Upvotes: 1