similar question has been asked at https://www.digitalocean.com/community/questions/how-do-i-keep-my-python-script-running but the solution mentioned there is to use screen. its not the solution. it doesn’t serve the purpose of running a pything script without logging in everyday. please help
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
Hi,
screen
works all the time no need to login, you can usenohup
toonohup python script.py &
.Also you can create a service for it if you are running Ubuntu 15.04 or newer you can create a simple systemd service file to run it as follows
Put these lines in a file called
hello.service
in/etc/systemd/system
.Make sure your script file is executable by running
sudo chmod +x <full_path_to_script>
Now reload systemd by running
sudo systemctl daemon-reload
, start the servicesudo systemctl start hello
.Now you can check if the service is running or not using
sudo systemctl status hello
and stop it usingsudo systemctl stop hello
I hope this helps you.
Depending on what your script is supposed to do, instead of running it on your computer, you could run it on something like a Raspberry Pi.
You could also run it online. There are various services that allow you to do that relatively easily. However, I don’t think many of them will allow you to run a script 24/7 (especially for free) and it is quite likely that even if they did, your script would stop running every time there was a maintenance. You can circumvent this by getting your own server.