FastAPI Uvicorn run without console

Viewed 1911

My Question is, is it possible to run uvicorn (fastapi) without a console? I use it, like in the tutorial, but people which use also my server close the console. How can i let it work in the background?

if __name__ == '__main__':
uvicorn.run("main:app", host="192.168.209.126", port=8080)

I tried to change my filename to main.pyw, but that didnt help

2 Answers

In Linux, you can use screen/tmux for running a task in background.

For example, with screen, you first open a new terminal by

screen -S new_screen

It brings you a terminal, run your code here.

python app.py

Then you press Ctrl + A + D for detaching, leave it run in background.

For more, see man page.

Related