X-Git-Url: https://git.kaliko.me/?p=python-daemon.git;a=blobdiff_plain;f=doc%2Fexamples%2Fdaemon-example.py;h=bb1855b78d555e01837b83463c5cf77994b8b5a1;hp=2baca825b214a2baf5e059a8fdf4d97ca0905843;hb=fc3dd8a7aa1e23891f29960fbb0fc6aa954514f5;hpb=319092ea606cf55e7d0fba14b191711e89e7444a diff --git a/doc/examples/daemon-example.py b/doc/examples/daemon-example.py index 2baca82..bb1855b 100755 --- a/doc/examples/daemon-example.py +++ b/doc/examples/daemon-example.py @@ -1,15 +1,29 @@ #!/usr/bin/env python import sys, time -from daemon import Daemon +from seth 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!') # message issued on self.stdout while True: time.sleep(1) + sys.stderr.write('œ unicode write test to stderr\n') + sys.stdout.write('write test to stdout\n') + + def shutdown(self): + """Overrides Daemon().shutdown() with some clean up""" + print("Stopping Daemon!") # message issued on self.stdout -if __name__ == "__main__": - daemon = MyDaemon('/tmp/daemon-example.pid') +if __name__ == '__main__': + daemon = MyDaemon('/tmp/daemon-example.pid', + '/tmp/daemon.log') if len(sys.argv) == 2: if 'start' == sys.argv[1]: daemon.start() @@ -18,9 +32,9 @@ if __name__ == "__main__": elif 'restart' == sys.argv[1]: daemon.restart() else: - print "Unknown command" + print('Unknown command') sys.exit(2) sys.exit(0) else: - print "usage: %s start|stop|restart" % sys.argv[0] + print("usage: {} start|stop|restart".format(sys.argv[0])) sys.exit(2)