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:
@@ -114,19 +114,25 @@ class Dispatcher:
|
|||||||
log.info("Stopped {} UpdateWorkerTasks".format(self.workers))
|
log.info("Stopped {} UpdateWorkerTasks".format(self.workers))
|
||||||
|
|
||||||
def add_handler(self, handler, group: int):
|
def add_handler(self, handler, group: int):
|
||||||
with self.lock:
|
async def fn():
|
||||||
if group not in self.groups:
|
async with self.lock:
|
||||||
self.groups[group] = []
|
if group not in self.groups:
|
||||||
self.groups = OrderedDict(sorted(self.groups.items()))
|
self.groups[group] = []
|
||||||
|
self.groups = OrderedDict(sorted(self.groups.items()))
|
||||||
|
|
||||||
self.groups[group].append(handler)
|
self.groups[group].append(handler)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(fn())
|
||||||
|
|
||||||
def remove_handler(self, handler, group: int):
|
def remove_handler(self, handler, group: int):
|
||||||
with self.lock:
|
async def fn():
|
||||||
if group not in self.groups:
|
async with self.lock:
|
||||||
raise ValueError("Group {} does not exist. Handler was not removed.".format(group))
|
if group not in self.groups:
|
||||||
|
raise ValueError("Group {} does not exist. Handler was not removed.".format(group))
|
||||||
|
|
||||||
self.groups[group].remove(handler)
|
self.groups[group].remove(handler)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(fn())
|
||||||
|
|
||||||
async def update_worker(self):
|
async def update_worker(self):
|
||||||
while True:
|
while True:
|
||||||
@@ -145,7 +151,7 @@ class Dispatcher:
|
|||||||
else (None, type(None))
|
else (None, type(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.lock:
|
async with self.lock:
|
||||||
for group in self.groups.values():
|
for group in self.groups.values():
|
||||||
for handler in group:
|
for handler in group:
|
||||||
args = None
|
args = None
|
||||||
|
Reference in New Issue
Block a user