I have a very long running Python program that I can manually start (and stop) from the command line. I do not want this program started automatically during system boot. But, after I manually start it running, I would like a way for my Pi to restart this Python program running again if it ever stops or exits for any reason, even if I'm logged out of my Pi. How can I do this?

1 Answer 1


If you have something you want to run for a long period you can use a terminal multiplexer like screen or tmux. They will continue to run after you have been disconnected from your Pi. As for keeping a process running for long running jobs you will want to wrap the command in a simple shell script. If you want to keep it a pure python code base you may want the process to run as a daemon. This is a great and very well documented example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.