I have a python script with GUI (using wxpython). I want to run it continuously on my (k)ubuntu system as a service. In case it exits due to some exception, I need it to restart automatically. I tried upstart but it immediately stops the service as soon as it starts.
Is there a super simple way to do this? (I tried restarting the python script within itself, tried simple shell scripts with infinite loops. But need something robust and reliable.)
Any help is greatly appreciated.
I know you said you tried shell scripts with infinite loops, but did you try using an "outer" Python script that runs perpetually as a service; it could just catch the exceptions and restart the Python GUI script if an exception were to occur.
Something like:
import myGUI
while True:
try:
myGUI.runGUICode() # make sure the execution stays in this loop
except:
pass # or do some recovery, initiallization, and logging here