Skip to content

Commit 0e57701

Browse files
committed
fix(dispatcher): mark tasks as done after taking elements off updates_queue
This commit fixes an issue where the `updates_queue.join()` method would never return. When waiting for the `updates_queue` to get emptied, the asyncio queue implementation relies on an internal counter. This counter is incremented on each `put()` but is not automatically decremented on each `get()`. In order to decrement the counter we need to use `updates_queue.task_done()`, as per the [docs](https://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue.task_done). Since this wasn't done in pyrogram yet, there was no proper way to use the `join()` method on the updates_queue and hence wait until all updates got processed. A workaround would be to use a while loop and check if `updates_queue.empty()` returns true. But using `join()` is just a lot cleaner and does not require a loop on our end.
1 parent efac171 commit 0e57701

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pyrogram/dispatcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,5 @@ async def handler_worker(self, lock):
257257
pass
258258
except Exception as e:
259259
log.exception(e)
260+
finally:
261+
self.updates_queue.task_done()

0 commit comments

Comments
 (0)