0

I am working on Ubuntu 16.04 and I have a python running process in the background

python myFunction.py

From time to time, myFunction process gets killed for unknown reason, however, I want to restart it automatically. I have multiple python process running in the background, and I do not know which one runs myFunctions.py (e.g. by using the pgrep command).

Is it possible? Can I make a bash or python script to restart the command python myFunction.py whenever the python process running it gets killed?

1 Answer 1

2

You can look at Supervisord which is (from its own documentation) :

a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems

Supervisord will keep your script in check. If it crashes, it will restart it again. If your raspberry reboots it will make sure the scripts starts automically after booting.

It works based on a config file formatted like this (more info in the docs) :

[program:myFunction]
command=/path_to_script/myFunction.py
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/myFunction.log
stderr_logfile=/var/log/myFunction.error.log
directory=/path_to_script

I hope this will help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.