Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding Pyrogram handlers during execution of a Pyrogram callback #17

Open
JosXa opened this issue Oct 23, 2020 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@JosXa
Copy link
Owner

JosXa commented Oct 23, 2020

Pyrogram has a problem where it uses an asyncio mechanism to first acquire the locks responsible for safe handler manipulations when calling client.add_handler, but at least one of these locks will be used when Pyrogram executes a callback.
This means that there is categorically a deadlock when attempting to add a handler inside of a handler callback. Dan's way around that is to have an async helper function to acquire all locks and then add the handler, which is executed as fire-and-forget (asynchronously):

https://github.com/pyrogram/pyrogram/blob/332468d271896e2c81b1a283b6a0f14fc1a666c1/pyrogram/dispatcher.py#L137-L152

This however means that client.add_handler will always have effect only after the dispatcher is done executing the current callback, making it unusable for tgintegration. For the 1.0 release, this was not an issue as it's only advertised as a test framework and automation tool and not for userbots, but should be looked into in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant