From 065719c8d830816246f02334836cd1ce84bab6f6 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 3 Jun 2019 19:44:43 +0200 Subject: [PATCH] conversation.cancel() now raises cancelled on future calls (#1183) --- telethon/tl/custom/conversation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telethon/tl/custom/conversation.py b/telethon/tl/custom/conversation.py index 343bf6ec..9df1bf58 100644 --- a/telethon/tl/custom/conversation.py +++ b/telethon/tl/custom/conversation.py @@ -55,6 +55,7 @@ class Conversation(ChatGetter): self._pending_reads = {} self._exclusive = exclusive + self._cancelled = False # The user is able to expect two responses for the same message. # {desired message ID: next incoming index} @@ -354,6 +355,9 @@ class Conversation(ChatGetter): raise ValueError('No message was sent previously') async def _get_result(self, future, start_time, timeout, pending, target_id): + if self._cancelled: + raise asyncio.CancelledError('The conversation was cancelled before') + due = self._total_due if timeout is None: timeout = self._timeout @@ -371,6 +375,7 @@ class Conversation(ChatGetter): del pending[target_id] def _cancel_all(self, exception=None): + self._cancelled = True for pending in itertools.chain( self._pending_responses.values(), self._pending_replies.values(), @@ -399,6 +404,7 @@ class Conversation(ChatGetter): raise errors.AlreadyInConversationError() conv_set.add(self) + self._cancelled = False self._last_outgoing = 0 self._last_incoming = 0