def testCWinSVProgram(): dictParam = { 'cmdExec': u'ping juchecar.com', # -t #dir C:\\ 'cmdTitle': u'\u8f6c\u9001\u884c\u60c5\u4fe1\u606f\u5230Redis', 'endFlag': u'JustForEnd', 'err2out': u'True', 'groupId': u'groupId', 'programId': u'ProgramId', 'logDir': u'D:\\WeiYFGitSrc\\PythonProject\\WeberEgg\\GitHub_PythonEggs\\weberWinSV\\weberWinSV\\test\\log\\', 'workDir': u'D:\\WeiYFGitSrc\\PythonProject\\WeberEgg\\GitHub_PythonEggs\\weberWinSV\\weberWinSV\\test\\' } c = CWinSVProgram(dictParam) c.CheckStopFileExists() c.CheckPidFileExists() c.GetRedirectCmd() c.GetPidFileTimeInt() c.GetLogFileInfo() print ReadTailLines(c.sLogOutFile, 3) #10 c.CrtDelStopFile("CRT") PrintAndSleep(10, "*** CrtDelStopFile") c.CrtDelStopFile("DEL") print c.CheckAndRunOneCmd()
def DoLoopOneSecondLogic(self): self.iOneSecondClock += 1 PrintAndSleep(1, 'DoLoopOneSecondLogic.iOneSecondClock=%d' % self.iOneSecondClock, self.iOneSecondClock % 600 == 1) #10分钟打印一次日志 if self.sSuffix == 'Test': self.TestLaunchTraverseCount(self.iOneSecondClock) pass
def GetFmQueue(self, sThreadName): while True: try: dictObj = self.queue.get(timeout=0.1) #timeout 0.1s self.queue.task_done() return dictObj except Empty: #如果 Queue 是空,就会出异常 PrintAndSleep(0.1, '%s.GetFmQueue' % sThreadName, False) #避免过多日志 return None
def run(self ): #Overwrite run() method, put what you want the thread do here iLoopCnt = 0 while not self.gef.IsExitFlagTrue(): iLoopCnt += 1 try: if self.cbLoopRun: self.cbLoopRun(iLoopCnt) else: PrintAndSleep(1, "%s.Just4Debug" % (self.getName())) except Exception, e: PrintTimeMsg("CStartLoopThread.Exception:%s" % (str(e))) raise
def LoopCRepeatRunMany(sFNameConfig="configCmd.json"): #WeiYF.20150610 该功能实现后,事实上就可以将 rrfw = CRepeatRunForWeb(sFNameConfig) iCnt = 0 while True: bRet = rrfw.ProgramCheckRun() # rrfw.ProgramRestartOne("TestHandleTradeFmRedis") # rrfw.ProgramQueryAll() # iCnt += 1 bVerbose = iCnt % 60 == 0 PrintAndSleep( 10, "*** LoopCRepeatRunMany.ProgramCheckRun(iCnt=%s)" % (iCnt), bVerbose)
def testThreadMain(): import signal gef = CGlobalExitFlag() def SetGlobalFlagToQuit(errno): global gef gef.SetExitFlagTrue("SetGlobalFlagToQuit.errno=%d" % errno) sys.exit(errno) def sig_handler(signum, frame): global gef gef.SetExitFlagTrue("receive a signal %d" % signum) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) gQueueSend = CQueueObject('Send') gQueueSend.PutToQueue(['Cmd0', 'Cmd1', 'Cmd2']) PrintAndSleep(1, 'waitThread') threadSend = CQueueThread(gef, gQueueSend, None) threadSend.start() #threadDeal.join() #加上之后就不退出了 PrintAndSleep(3, 'testThreadMain')
def LoopAndWatchPrograms(self): iLoopCnt = 0 while True: os.chdir(self.sStartCWD) #回到启动时的目录 iLoopCnt += 1 iStart,iStop = 0,0 for oWinSV in self.lsWinSV: iChg = oWinSV.CheckAndRunOneCmd() if iChg>0: iStart += 1 if iChg<0: iStop += 1 if iStart>0 or iStop>0: PrintTimeMsg("LoopAndWatchPrograms#%d.iStart=%s,iStop=%s!" % ( iLoopCnt,iStart,iStop)) PrintAndSleep(self.iCheckIntervalSeconds, "LoopAndWatchPrograms.iLoopCnt=%s=" % (iLoopCnt), iLoopCnt%10 == 0)
def testTCmdPipeClient(): # c = TCmdPipeClient('127.0.0.1:8805') #c = TCmdPipeClient('127.0.0.1:9801') c = TCmdPipeClient('192.168.2.199:9801') iCnt = 0 while iCnt < 5: # bRet = c.SendPipeRequest(['Test','One','2','three','iCnt=%d' % iCnt]) bRet = c.SendPipeRequest( ['*', 'Test', 'One', '2', 'three', 'iCnt=%d' % iCnt]) if not bRet: PrintTimeMsg("testTCmdPipeClient.SendPipeRequest.Error.iCnt=%d" % (iCnt)) break PrintAndSleep(6, 'testTCmdPipeClient.iCnt=%d!' % iCnt) iCnt += 1
def WaitAndCheck(self, sHint, cbCheckFunc=None, iTimeoutSeconds=60): # 等待并调用某检查过程 iWaitCount = 0 while not self.IsExitFlagTrue(): PrintAndSleep(self.WAIT_SECONDS_SYN, 'WaitAndCheck.%s#%d' % (sHint, iWaitCount), iWaitCount % self.WAIT_SECONDS_LOG == 0) if cbCheckFunc: lsRet = cbCheckFunc(sHint, iWaitCount) if lsRet: return lsRet # cbFunc 返回非空列表,则直接返回对应值 else: PrintTimeMsg('WaitAndCheck.JustPrint.%s#%d' % (sHint, iWaitCount)) iWaitCount += 1 if iWaitCount > self.WAIT_SECONDS_NUM * iTimeoutSeconds: return ['WTO', 'WaitAndCheck.TimeOut'] return ['WSQ', 'WaitAndCheck.SigQuit']