我使用Sander Marechal的code sample成功守护了我的python代码。现在我想将stdout记录到logfile但是失败了。如何在daemonize之后记录stdout?这是我的代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import zerorpc, zmq
import os, sys, time
from daemon import Daemon
class RunTestCase(zerorpc.Subscriber):
def __init__(self, domain, *args, **kwargs):
super(RunTestCase, self).__init__(*args, **kwargs)
self.domain = domain
def add(self, domain, testcase_pk, testresult_pk):
print domain, testcase_pk, testresult_pk
if domain == self.domain:
print "NAT Got it"
class subscriberd(Daemon):
domain = ""
def run(self):
# Start RPC Server
s = RunTestCase(self.domain)
s._events.setsockopt(zmq.TCP_KEEPALIVE, 1)
s.connect("tcp://192.168.77.170:8888")
s.run()
if __name__ == "__main__":
daemon = subscriberd('/tmp/subscriber.pid', stdout='/tmp/subscriber.log')
#I add stdout here but /tmp/subscriber.log still empty after test.
daemon.domain = sys.argv[1]
if len(sys.argv) == 3:
if 'start' == sys.argv[2]:
daemon.start()
elif 'stop' == sys.argv[2]:
daemon.stop()
elif 'restart' == sys.argv[2]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s domain start|stop|restart" % sys.argv[0]
print "ex: %s KS-1 start" % sys.argv[0]
sys.exit(2)
答案 0 :(得分:0)
这就是我做的事情
Button::Button(const float &x, const float &y, gdl::Geometry *back,
gdl::Texture *tx, gdl::Texture *txS, glm::vec3 const &scale, void (OurMenu::*ptr)())
{
_select = new Bloc(0, 0, back, txS);
_select->rotate(glm::vec3(1, 1, 0), 180);
_select->setScale(scale);
_select->setX(x);
_select->setY(y);
_select->setZ(1);
_notSelect = new Bloc(0, 0, back, tx);
_notSelect->rotate(glm::vec3(1, 1, 0), 180);
_notSelect->setScale(scale);
_notSelect->setX(x);
_notSelect->setY(y);
_notSelect->setZ(-1);
doIt = ptr;
}
完整示例: