Usage Example

Example Daemon

Simple Daemon that sends a syslog message every 2 seconds, and terminates after two minutes:

from pep3143daemon import DaemonContext, PidFile
import syslog, time

counter = 60

pidfile = PidFile(pid)
daemon = DaemonContext(pidfile=pidfile)
# we could have written this also as:
# daemon.pidfile = pidfile

print('pidfile is: {0}'.format(pid))

syslog.syslog('pep3143daemon_example: daemonized')

while counter > 0:
    syslog.syslog('pep3143daemon_example: still running')
    counter -= 1
    syslog.syslog('pep3143daemon_example: counter: {0}'.format(counter))

syslog.syslog('pep3143daemon_example: terminating...')