From: kaliko Date: Sun, 23 Oct 2011 12:24:53 +0000 (+0200) Subject: improved example script X-Git-Tag: 0.4 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=541ee94a0a5ae51b7c2d6995a78e6cf86ec9ec25;p=python-daemon.git improved example script --- diff --git a/doc/examples/daemon-example.py b/doc/examples/daemon-example.py index 2baca82..87a80bc 100755 --- a/doc/examples/daemon-example.py +++ b/doc/examples/daemon-example.py @@ -4,12 +4,24 @@ import sys, time from daemon import Daemon class MyDaemon(Daemon): + + def __init__(self, pid, log): + Daemon.__init__(self, pid, stdout=log, stderr=log) + def run(self): + """Overrides Daemon().run() with actions you want to daemonize. + MyDaemon.run() is then called within MyDaemon().start()""" + print "Starting Deamon!" while True: time.sleep(1) + def shutdown(self): + """Overrides Daemon().shutdown() with some clean up""" + print "Stopping Daemon!" + if __name__ == "__main__": - daemon = MyDaemon('/tmp/daemon-example.pid') + daemon = MyDaemon('/tmp/daemon-example.pid', + '/tmp/daemon.log') if len(sys.argv) == 2: if 'start' == sys.argv[1]: daemon.start()