how to keep running python script all the time

similar question has been asked at 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


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hi, screen works all the time no need to login, you can use nohup too nohup python &.

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

Description=A test unit


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 service sudo systemctl start hello.

Now you can check if the service is running or not using sudo systemctl status hello and stop it using sudo 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.