【发布时间】:2013-04-27 00:20:20
【问题描述】:
我有一个使用 DaemonRunner 的脚本来创建一个带有 pid 文件的守护进程。问题是,如果有人试图在不停止当前正在运行的进程的情况下启动它,它将默默地失败。检测现有进程并提醒用户先停止它的最佳方法是什么?查pidfile就这么简单吗?
我的代码和这个例子类似:
#!/usr/bin/python
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/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()
要查看我的实际代码,请查看以下的investor.py: https://github.com/jgillick/LendingClubAutoInvestor
【问题讨论】:
标签: python python-2.7 python-daemon