【发布时间】:2012-05-28 11:29:33
【问题描述】:
我在两个不同的脚本中使用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 等基本内容保持不变。
【问题讨论】:
-
将常量保留在
App类中,并为每个应用创建一个子类
标签: python linux timer daemon runner