2
我有使用Python守護程序的舊版本創建了一個基本的Python守護進程和驗證碼:如何向python-daemon添加更多命令參數?
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()
現在一切工作正常,但我需要一個更可能的命令添加到我的守護進程。當前的默認命令是「啓動,停止,重啓」。我需要第四命令「mycommand的」執行時,將只運行這段代碼:
my_function()
print "Function was successfully run!"
我曾嘗試谷歌搜索和研究,但無法弄清楚我自己。我嘗試手動拾取參數,而不會陷入python-daemon代碼中,但是不能使其工作。
你有沒有得到這個工作?你嘗試過Riccardo的解決方案嗎? –