daemonService.py 623 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. import time
  3. import threading
  4. import pwd
  5. import signal
  6. class DaemonService:
  7. def __init__(self):
  8. self.stop_event = threading.Event()
  9. def run(self):
  10. while not self.stop_event.is_set():
  11. print("Daemon is running...")
  12. time.sleep(5)
  13. def start(self):
  14. self.stop_event.clear()
  15. thread = threading.Thread(target=self.run)
  16. thread.start()
  17. def stop(self):
  18. self.stop_event.set()
  19. def status(self):
  20. if self.stop_event.is_set():
  21. print("Daemon is not running.")
  22. else:
  23. print("Daemon is running.")