screen works all the time no need to login, you can use
nohup 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
Description=A test unit
Put these lines in a file called
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.