2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-30 13:57:54 +00:00

Fix asyncio lock not being awaited properly

This commit is contained in:
Dan 2019-06-21 21:48:35 +02:00
parent 471a124d2c
commit 2ba445d21e

View File

@ -114,20 +114,26 @@ class Dispatcher:
log.info("Stopped {} UpdateWorkerTasks".format(self.workers))
def add_handler(self, handler, group: int):
with self.lock:
async def fn():
async with self.lock:
if group not in self.groups:
self.groups[group] = []
self.groups = OrderedDict(sorted(self.groups.items()))
self.groups[group].append(handler)
asyncio.get_event_loop().run_until_complete(fn())
def remove_handler(self, handler, group: int):
with self.lock:
async def fn():
async with self.lock:
if group not in self.groups:
raise ValueError("Group {} does not exist. Handler was not removed.".format(group))
self.groups[group].remove(handler)
asyncio.get_event_loop().run_until_complete(fn())
async def update_worker(self):
while True:
packet = await self.updates_queue.get()
@ -145,7 +151,7 @@ class Dispatcher:
else (None, type(None))
)
with self.lock:
async with self.lock:
for group in self.groups.values():
for handler in group:
args = None