Module daemon
[hide private]
[frames] | no frames]

Module daemon

source code

Overview

Convert the calling process to a daemon. To make the current Python process into a daemon process, you need two lines of code:

   import daemon
   daemon.daemonize()

If daemonize() fails for any reason, it throws an exception. It also logs debug messages, using the standard Python 'logging' package, to channel 'daemon'.

Adapted from:

See Also

Stevens, W. Richard. Unix Network Programming (Addison-Wesley, 1990).


Version: 1.0

Author: Brian Clapper, bmc@clapper.org

Copyright: (c) 2008 Brian M. Clapper

License: BSD-style license

Classes [hide private]
  DaemonException
Thrown by daemonize() when an error occurs while attempting to create a daemon.
Functions [hide private]
 
daemonize(noClose=False)
Convert the calling process into a daemon.
source code
 
_fork() source code
 
_redirectFileDescriptors() source code
Variables [hide private]
  __url__ = 'http://www.clapper.org/software/python/daemon/'
  UMASK = 0
  WORKDIR = '/'
  MAXFD = 1024
  NULL_DEVICE = '/dev/null'
  logger = logging.getLogger('daemonize')
Function Details [hide private]

daemonize(noClose=False)

source code 

Convert the calling process into a daemon.

Parameters:
  • noClose (boolean) - If True, don't close the file descriptors. Useful if the calling process has already redirected file descriptors to an output file. WARNING: Only set this parameter to True if you're SURE there are no open file descriptors to the calling terminal. Otherwise, you'll risk having the daemon re-acquire a control terminal, which can cause it to be killed if someone logs off that terminal.
Raises: