示例#1
0
 def addevent(self, pid=-1):
     if pid == -1:
         for p in self._procs.itervalues():
             p.event = event(self.pesys.evs, self.pesys.tms, p.chanel)
             p.event.add_read(self.recvfromworker)
     else:
         if self._procs.has_key(pid):
             p = self._procs[pid]
             p.event = event(self.pesys.evs, self.pesys.tms, p.chanel)
             p.event.add_read(self.recvfromworker)
         else:
             self.log.logError("Pyproc", "pid(%d) not in pyproc" % pid)
示例#2
0
 def recvmsg(self, c):
     buf = self.c.read()
     self.log.logInfo("CmdServer", "Send cmd[%s] to worker", buf.strip())
     self.proc.sendcmd(buf)
     self.ev = event(self.evs, self.tms)
     self.ev.add_timer(
         5000, self.timeouthandler)  # set cmd response timeout to 5s
示例#3
0
 def sendcmd(self, cmd, args):
     buf = cmd + " "
     for arg in args:
         buf += (arg + " ")
     self.c.write(buf)
     self.ev = event(self.evs, self.tms)
     self.ev.add_timer(10000, self.timeouthandler) # set cmd response timeout to 5s
示例#4
0
def master_mainloop(pesys):
    pesys.initsys("master")

    log = pesys.log
    proc = pesys.proc
    evs = pesys.evs
    tms = pesys.tms
    cmdserver(pesys)
    exiting = False
    t_quit = event(evs, tms)

    proc.addevent()

    while 1:
        try:
            t = tms.processtimer()
            evs.processevent(t)
        except:
            log.logInfo("Master", "tms or evs runtime error: %s", traceback.format_exc())

        if pesys.stop and not exiting: # stop right now
            log.logNotice("Master", "master process stop ...")
            proc.sendsig(signal.SIGKILL)
            exiting = True

        if pesys.quit and not exiting: # stop process new task and wait for old task process over
            log.logNotice("Master", "master process quit ...")
            proc.sendcmd("quit")
            exiting = True
            t_quit.add_timer(10000, quittimeout)
            t_quit.proc = proc

        if pesys.reopen: # reopen log
            log.logNotice("Master", "master process reopen ...")
            pesys.reopen = False
            proc.sendcmd("reopen")
            log.reopen()

        if pesys.reload: # reload config
            pesys.reload = False
            log.logNotice("Master", "master process reload ...")
            proc.sendcmd("reload")

        if pesys.reap: # deal sig with SIGCHLD
            pesys.reap = False

        proc.wait(exiting) # process SIGCHLD

        if exiting:
            if pesys.quit and not proc.checkalive():
                log.logNotice("Master", "All worker process exited, master quit")
                proc.closechanel()
                os.remove(pesys.pidpath)
                sys.exit(0)
            if pesys.stop:
                log.logNotice("Master", "All worker process stoped, master stop")
                os.remove(pesys.pidpath)
                sys.exit(0)
示例#5
0
 def recvmsg(self, c):
     buf = self.c.read()
     self.log.logInfo("CmdServer", "Send cmd[%s] to worker", buf.strip())
     self.proc.sendcmd(buf)
     self.ev = event(self.evs, self.tms)
     self.ev.add_timer(5000, self.timeouthandler) # set cmd response timeout to 5s
示例#6
0
文件: workercmd.py 项目: AlexWoo/pyed
 def __init__(self, log, evs, tms, chanel):
     self._log = log
     self._cmd = {}
     self._ev = event(evs, tms, chanel)
     self._ev.add_read(self.processcmd)
示例#7
0
 def __init__(self, log, evs, tms, chanel):
     self._log = log
     self._cmd = {}
     self._ev = event(evs, tms, chanel)
     self._ev.add_read(self.processcmd)