If this is a one-time task (that is, you are not creating a software product) I would quick-and-dirty use a combination of shell scripting and a terminal multiplexer like screen. For restarting processes that died (that is, they emitted an exit code other than 0
), just use the shell.
Start your processes for example like this:
for i in n/*; do
screen -d -m -L -S $i -t $i until python sc.py $i; do echo "Crashed with exit code $?. Respawning.." >&2 ; sleep 1 ; done
done
This would
- Create a new screen session for every file in the subdirectory
n/
running your script,
- Restart your python script unless it exited successfully (using Bash's
until
)
- Set the title (
-t
) and session name (-S
) to the input file name,
- And turn on logging of all the output for later inspection if something went wrong (
-L
).
You can then use normal screen commands like screen -list
to list all running tasks and screen -r <session name>
to view the running session output.