Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
d-Rickyy-b committed Jul 16, 2023
commit 0e5770105a54c866bdfc2fa8b8efe6d432b18dd9
2 changes: 2 additions & 0 deletions pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,5 @@ async def handler_worker(self, lock):
pass
except Exception as e:
log.exception(e)
finally:
self.updates_queue.task_done()