def reg(self, funtype, fun, deadtime = (2038, 1, 1), index = -1): ''' 注册一个回调函数 @param funtype:函数类型 @param fun:回调函数 @param deadtime:过期时间 @param index:索引 ''' # 判断过期 ddt = Time.as_datetime(deadtime) if ddt <= datetime.datetime.now(): return if funtype not in self.fundict: callback = self.fundict[funtype] = Callback() else: callback = self.fundict[funtype] callback.reg(fun, deadtime, index)
def reg(self, fun, deadtime = (2038, 1, 1), index = -1): ''' 注册一个函数 @param fun:函数对象 @param deadtime:过期时间 @param index:索引 ''' # 判断过期 ddt = Time.as_datetime(deadtime) if ddt <= datetime.datetime.now(): return # 检测是否重复 if fun in self.fun_list: print "GE_EXC, repeat reg function(%s, %s)" % (fun.__module__, fun.__name__) return # 按照索引插入 if index < 0: self.fun_list.append(fun) else: self.fun_list.insert(index, fun)