This repository was archived by the owner on Dec 23, 2024. It is now read-only.
fix(dispatcher): mark tasks as done after taking elements off queue#1305
Open
d-Rickyy-b wants to merge 1 commit intopyrogram:masterfrom
Open
fix(dispatcher): mark tasks as done after taking elements off queue#1305d-Rickyy-b wants to merge 1 commit intopyrogram:masterfrom
d-Rickyy-b wants to merge 1 commit intopyrogram:masterfrom
Conversation
…_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the
updates_queue.join()method would never return. When waiting for theupdates_queueto get emptied, the asyncio queue implementation relies on an internal counter. This counter is incremented on eachput()but is not automatically decremented on eachget(). In order to decrement the counter we need to useupdates_queue.task_done(), as per the docs. Since this wasn't done in pyrogram yet, there was no proper way to use thejoin()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 usingjoin()is just a lot cleaner and does not require a loop on our end.