You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
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.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: