def SecondTick(): ''' 秒级别定时器 :return: ''' secondevent = gevent.event.Event() def SecondTickProcess(): nowtime2 = datetime.now() Log.Write("SecondTickProcess", nowtime2) while True: secondevent.wait(1) # 一秒之后执行 SecondTickProcess() # 秒级别执行函数 DBEngine.UpdateCurrentSession() Lock1.ClearCurrent()
def SpawTickTimer(tick, func): ''' 创建一个循环时间的定时器 :param tick: 秒数 :param func: 函数 :return: ''' timerevent = gevent.event.Event() while True: timerevent.wait(tick) try: func() except Exception, e: Log.Write(e) Log.Write(traceback.format_exc()) DBEngine.UpdateCurrentSession() Lock1.ClearCurrent()
:param time: :param func: :param param: :return: ''' timerevent = gevent.event.Event() timerevent.wait(time) try: if param: func(param) else: func() except Exception, e: Log.Write(e) Log.Write(traceback.format_exc()) DBEngine.UpdateCurrentSession() Lock1.ClearCurrent() @staticmethod def CreateTickTimer(tick, func): ''' 创建循环级别定时器 :param tick: :param func: :return: ''' gevent.spawn(TimerManager.SpawTickTimer, tick, func) @staticmethod def CreateOneTimer(time, func, param): '''