def start_reading(loop: asyncio.AbstractEventLoop, redis: Redis): """ Simple functions to monitoring data from channels for debug Works if DEBUG mode is enabled """ channels = [] for t in all_tasks: res = loop.run_until_complete( redis.subscribe(f'channel:{t.redis_channel}')) channels.append(res[0]) for ch in channels: loop.create_task(reader(ch))
def _handle_event(self, connection: Redis, event_result): done, pending = event_result for task in done: if task is self.closed_event_wait: self.closed_event_wait = None raise StopException("Closed event") if task is self.add_event_wait: self.add_callback_event = asyncio.Future() self.add_event_wait = asyncio.ensure_future(self.add_callback_event) tup = task.result() ix = next((i for i, v in enumerate(self.callbacks) if v is tup), None) if ix is None: continue asyncio.ensure_future( asyncio.gather(*(connection.psubscribe(i) if i.is_pattern else connection.subscribe(i) for i in map(operator.itemgetter(1), self.callbacks[ix:]))))