fix(dispatcher): mark tasks as done after taking elements off queue #1305
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_queue
to 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.