Python and Daemons
justin at iago.org
Fri Feb 22 17:20:54 EST 2002
Dieter Lunn <theguru at mb.sympatico.ca> writes:
> I was wondering how to write a linux daemon using Python.
This is what I use:
'''file-like dummy device, used for daemonization
writes are redirected into our logging object'''
def write(self, s):
"cause this process to becaome a daemon"
if os.fork() != 0:
if os.fork() != 0: # 2nd fork is widely recommended
os._exit(0) # though not always needed
os.chdir("/") # not strictly necessary, but a good idea
sys.stdout = Log_out()
sys.stderr = Log_out()
debugmsg is a local function which calls a function in my logging library.
More information about the Python-list