From 04cf2953f6a85f89fc65870b4ad8f7f9ee0e4304 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 3 Oct 2022 10:24:37 +0200 Subject: [PATCH] Document that disconnect cancels event handlers Closes #3942. --- telethon/client/telegrambaseclient.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 1f0d75e6..28e4485b 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -591,6 +591,12 @@ class TelegramBaseClient(abc.ABC): coroutine that you should await on your own code; otherwise the loop is ran until said coroutine completes. + Event handlers which are currently running will be cancelled before + this function returns (in order to properly clean-up their tasks). + In particular, this means that using ``disconnect`` in a handler + will cause code after the ``disconnect`` to never run. If this is + needed, consider spawning a separate task to do the remaining work. + Example .. code-block:: python