Skip to content

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 2 years ago2K views
1 Answer
3
Accepted Answer

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

AWS
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
AWS
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years 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.