kibot.daemon
index
/usr/src/rpm/BUILD/kibot-0.0.12/kibot/daemon.py

 
Modules
       
os
sys

 
Functions
       
cleanup_old_lockfile(filename)
clean up an existing lockfile, which contains a pid.  If the file
does not exist, or the process has terminated (and lockfile removed),
cleanup_lock will return 1.  If the process exists, or is not KNOWN to be
done, return 0.
 
This is safe to call BEFORE you even try to create the lockfile,
but you should still use safe lockfile creation.  For example:
 
  if not cleanup_old_lockfile(filename): sys.exit('lockfile exists')
  if not lock_file(filename): sys.exit('lockfile exists')
 
If the latter fails, it's because the lockfile was created BETWEEN the
two calls.
daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null')
This forks the current process into a daemon.
The stdin, stdout, and stderr arguments are file names that
will be opened and be used to replace the standard file descriptors
in sys.stdin, sys.stdout, and sys.stderr.
These arguments are optional and default to /dev/null.
Note that stderr is opened unbuffered, so
if it shares a file with stdout then interleaved output
may not appear in the order that you expect.
lock_fd(filename, mode=511)
get a file descriptor (NOT a file object) for a lockfile
The check/create operation is performed atomically to avoid race
conditions.
lock_file(filename, contents=None, mode=511)
test_daemonize()
This is an example main function run by the daemon.
This prints a count and timestamp once per second.
test_lockfiles()
unlock_file(filename)