Skip to content Skip to sidebar Skip to footer

Python Daemonize

I would like to daemonize a python process, and now want to ask if it is good practice to have a daemon running, like a parent process and call another class which opens 10-30 thre

Solution 1:

Solution 2:

You can use supervisord for this. You can configure tasks to respond to events. The events can be manually created or automatically by monitoring processes or based on regular intervals.

It is fully customizable and written in Python.

Example:

[program:your_daemon_name]command=your_daemon_process
# Add extra options here according to the manual...[eventlistener:your_monitor_name]command=your_monitor_process
events=PROCESS_STATE_RUNNING # Will be triggered after a program changes from starting to running# Add extra options here according to the manual...

Or if you want the eventlistener to respond to the process output use the event PROCESS_COMMUNICATION_STDOUT or TICK_60 for a check every minute. The logs can be redirected to files and such so you can always view the state.

Solution 3:

There's really not much to creating your own daemonize function: The source for Advanced Programming in the Unix Environment (2nd edition) is freely available: http://www.apuebook.com/src.tar.gz -- you're looking for the apue.2e/daemons/init.c file.

There is a small helper program that does all the work of creating a proper daemon, it can be used to wrap arbitrary programs; this might save some hassle.

Post a Comment for "Python Daemonize"