Forking, daemonizing and monitoring a python script
I have a python script sc.py on my debian server. I would like : To run it as a daemon and keep it running indefinitely To run it N times (as sub processes, children, forks) in // To monitor the whole processes (in order to restart any dying process) Do you know software that would enable me to do so? I don't know if I have to look for a solution on the python side (any python module or configuration) or if there is a debian package somewhere which does that job?
You can use supervisord for this. It daemonizes Python processes for you, and also handles subprocesses.
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.
How to check if list1 contains some elements of list2?
Python logging from multiple modules to same log file
Python drag and drop, get filenames [closed]
Upload multiple files with Tornado Web Server and Nginx
How to read a simple binary file
How to run mysql in Django 1.5.5 with Python 3.3.4 in Windows 7
How can I do maps involving string fields in rethinkdb?
Scrollbar not functioning properly Tkinter
Is there a way to quickly create many files many sequential files (ex1 . . . ex 50) in Python?
Pygame playing sound with pygame.mixer.music.load(file) gives NoneType error
How to update multiple values in Mongodb using pymongo?
Manually return an error result and status failure for a celery task?
Python backtrace from C++ embedded in Python
Find nth smallest element in numpy array [duplicate]
How to extract array from the first element of triples in 2d array of triples using numpy
Simulate user clicking in QSystemTrayIcon