Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep a Python application running in an EC2 instance?

I have a python application which I uploaded to an EC2 instance as a file named "example.py". I want this code to be running continuously, as it has a while loop that calls a 3rd party Twitter API every minute. If I run "python3 example.py", and close the terminal, the SSH session terminates. Will the python application continue running in that EC2 instance? How can I make that sure? Thanks.

like image 929
ThePumpkinMaster Avatar asked Feb 16 '26 05:02

ThePumpkinMaster


1 Answers

Quick Solution - You run in SSH terminal:

nohup python3 example.py & 

(best if you don't wanna see what is going on later)

or

Best Solution - You create a Screen in SSH terminal:

screen

Then you press ctrl+a+d to detach from it. Then you can close SSH safely. If you want to see what is going on later, you can just:

screen -r
like image 105
Gabriel Panza Avatar answered Feb 18 '26 19:02

Gabriel Panza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!