def run_tasks(self, loop, login_info=None): def onData(_type, _name, _data, *args, **kwargs): if not _type or not _name or not _data: return if _type not in self.data: return _time = int(time.time()) # only update the data which is expired if _name in self.data[_type] and \ _time - self.data[_type][_name]["time"] < self.expired: return # print("use:", _type, _name) self.data[_type][_name] = _data self.pusher = Pusher(loop, login_info) self.pusher.sync_subscribe(onData, self.topic)
def init_pusher(self, loop): self.future_pusher = asyncio.Future() self.pusher = Pusher(loop, co=self.__init_pusher) loop.run_until_complete(asyncio.wait_for(self.future_pusher, 999))