看看runner模块的代码,下面的代码应该行得通。。。我在定义stdout和stderr时遇到问题。。。你能测试一下吗?在from daemon import runner
import time
# Inerith from the DaemonRunner class to create a personal runner
class MyRunner(runner.DaemonRunner):
def __init__(self, *args, **kwd):
super().__init__(*args, **kwd)
# define the function that execute your stuff...
def _mycommand(self):
print('execute my command')
# tell to the class how to reach that function
action_funcs = runner.DaemonRunner.action_funcs
action_funcs['mycommand'] = _mycommand
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()
# bind to your "MyRunner" instead of the generic one
daemon_runner = MyRunner(app)
daemon_runner.do_action()