白衣染霜花
下面是我在开发一个新的守护进程时使用的基本的‘HowdyWorld’Python守护进程。#!/usr/bin/pythonimport timefrom daemon import runnerclass App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/foo.pid'
self.pidfile_timeout = 5
def run(self):
while True:
print("Howdy! Gig'em! Whoop!")
time.sleep(10)app = App()daemon_runner = runner.DaemonRunner(app)daemon_runner.do_action()注意,您将需要python-daemon图书馆。您可以通过以下方式安装它:pip install python-daemon那就从./howdy.py start,停止这一切./howdy.py stop