keep venv & python3 -m uvicorn api:app running in the background in EC2

0

We use venv in Ubuntu to run FastAPI as an endpoint on EC2.

Here are the steps I follow:

source .venv/bin/activate
python3 -m uvicorn api:app

The endpoint works well as long as I keep the terminal open, but when I close the terminal, I get a 502 Bad Gateway error.

What is the solution to keep python3 -m uvicorn api:app running in the background even when I'm not on the terminal?

已提問 2 個月前檢視次數 404 次
1 個回答
3
已接受的答案

Hi,

In linux, to run any command in background put an & at the end of the command and also consider using nohup.

As an example, please see below:

nohup python3 -m uvicorn api:app &

You should now be able to see the process running in the output of the below command:

ps -ef

Hope this helps!

Thanks, Rama

profile pictureAWS
專家
已回答 2 個月前
profile picture
專家
已審閱 2 個月前
profile pictureAWS
專家
iBehr
已審閱 2 個月前
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南