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?

asked 4 days ago96 views
1 Answer
2

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
Rama
answered 4 days ago
profile picture
EXPERT
reviewed 4 days ago
profile pictureAWS
EXPERT
iBehr
reviewed 4 days ago
EXPERT
reviewed 4 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions