Skip to content

Commit 227a5aa

Browse files
committed
Add FAQ about why stop, restart, add/remove_handler could make the code hang
1 parent 0123690 commit 227a5aa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/source/faq.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ contact people using official apps. The answer is the same for Pyrogram too and
253253
for usernames, meeting them in a common group, have their phone contacts saved or getting a message mentioning them,
254254
either a forward or a mention in the message text.
255255

256+
Code hangs when I stop, restart, add/remove_handler
257+
---------------------------------------------------
258+
259+
You tried to ``.stop()``, ``.restart()``, ``.add_handler()`` or ``.remove_handler()`` *inside* a running handler, but
260+
that can't be done because the way Pyrogram deals with handlers would make it hang.
261+
262+
When calling one of the methods above inside an event handler, Pyrogram needs to wait for all running handlers to finish
263+
in order to safely continue. In other words, since your handler is blocking the execution by waiting for the called
264+
method to finish and since Pyrogram needs to wait for your handler to finish, you are left with a deadlock.
265+
266+
The solution to this problem is to pass ``block=False`` to such methods so that they return immediately and the actual
267+
code called asynchronously.
268+
256269
UnicodeEncodeError: '<encoding>' codec can't encode …
257270
-----------------------------------------------------
258271

0 commit comments

Comments
 (0)