From 541ee94a0a5ae51b7c2d6995a78e6cf86ec9ec25 Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 23 Oct 2011 14:24:53 +0200 Subject: [PATCH] improved example script --- doc/examples/daemon-example.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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() -- 2.39.5