How to auto-restart a python script on fail?

Posted by norm on Stack Overflow See other posts from Stack Overflow or by norm
Published on 2010-04-26T15:00:24Z Indexed on 2010/04/26 15:03 UTC
Read the original article Hit count: 302

Filed under:
|
|
|
|

This post describes how to keep a child process alive in a BASH script:

http://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies

This worked great for calling another BASH script.

However, I tried executing something similar where the child process is a Python script:

#!/bin/bash

PYTHON=/usr/bin/python2.6

function myprocess {


$PYTHON daemon.py start

}
NOW=$(date +"%b-%d-%y")

until myprocess; do
     echo "$NOW Prog crashed. Restarting..." >> error.txt
     sleep 1
done

Now the behaviour is completely different. It seems the python script is no longer a child of of the bash script but seems to have 'taken over' the BASH scripts PID - so there is no longer a BASH wrapper round the called script...why?

© Stack Overflow or respective owner

Related posts about bash

Related posts about python