def _Clear(self): """清空redis中的记录""" count = len(self.pd_task) for i in range(count): key = getResultName(i) myredis.delkey(key) myredis.delkey('multi')
def PostTask(fn, t, reset=False): """每隔t秒执行一次fn 主要是防止交易接口被短期内多次调用, 造成系统异常 """ key = 'posttask_'+fn.func_name cur_t = agl.curTime() if reset: myredis.delkey(key) pre_t = myredis.get_obj(key) if pre_t == None: pre_t = cur_t - datetime.timedelta(seconds=t+1) if cur_t - pre_t > datetime.timedelta(seconds=t): fn() myredis.set_obj(key, cur_t)