我在两个不同的脚本中使用template python daemon discussed here来启动两个单独的守护进程。我想将它们合并成一个具有一个锁文件的守护进程脚本等。但是,每个守护进程都有不同的循环计时器,一个在1分钟,另一个在5分钟。我从这开始:
import os
import subprocess
import time
from daemon import runner
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/test.pid'
self.pidfile_timeout = 5
def run(self):
try:
while True:
print "hello!"
# set the sleep time for repeated action here:
time.sleep(1)
except Exception, e:
raise
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()显而易见的事情是创建另一个类,但我希望像pidfile这样的基本东西保持不变。