test.py 766 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import time
  5. from demeter.core import *
  6. from daemon import Daemon
  7. class MyTestDaemon(Daemon):
  8. def run(self):
  9. sys.stdout.write('Daemon started with pid {}\n'.format(os.getpid()))
  10. while True:
  11. sys.stdout.write('Daemon Alive! {}\n'.format(time.ctime()))
  12. sys.stdout.flush()
  13. time.sleep(5)
  14. if __name__ == '__main__':
  15. daemon = MyTestDaemon(key='deamon')
  16. if len(sys.argv) != 2:
  17. print('Usage: {} [start|stop]'.format(sys.argv[0]), file=sys.stderr)
  18. raise SystemExit(1)
  19. if 'start' == sys.argv[1]:
  20. daemon.start()
  21. elif 'stop' == sys.argv[1]:
  22. daemon.stop()
  23. elif 'restart' == sys.argv[1]:
  24. daemon.restart()
  25. else:
  26. print('Unknown command {!r}'.format(sys.argv[1]), file=sys.stderr)
  27. raise SystemExit(1)