Daemonizing a Python Program

Dave Brueck dbrueck at edgix.com
Tue Nov 14 15:27:58 CET 2000


Coy wrote:
> I've been toying around with the SocketServer module to get a
> feel from
> creating servers and haven't found a method for making the program
> daemonic. I've searched through the library docs and only find daemons
> in the Thread module.  Is there not a standard library function/method
> for this? Is there a good one around or do I just need to hack one up
> from the UNIX FAQ?

Hi Coy,
I don't think there's a standard way to do this (You could make a tiny C
extension module just to call daemon()... yech), but do you really need to
be a system daemon or do you just want to run in the background?

Most likely, the latter will suffice. I have a SocketServer-based program
running on a bunch of nodes in a network (they listen for work requests, do
some processing, and return the finished work) and I always just run them in
the background, usually started by a cron job calling a simple script:

#!/bin/sh

# Insert checks here to see if it's already running. If so, exit

# It's not running, so start it
python YourCoolProg.py > /dev/null 2>&1 &

-Dave






More information about the Python-list mailing list