From 468ebf50cf596b73175aa5826a44e5be00becb78 Mon Sep 17 00:00:00 2001 From: Nyan <93275906+el-garro@users.noreply.github.com> Date: Sun, 18 Sep 2022 11:24:51 -0400 Subject: [PATCH] Add tempfile deletion in case of asyncio task cancellation. (#1080) --- pyrogram/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyrogram/client.py b/pyrogram/client.py index d30a5e9a..f4cee803 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -737,6 +737,12 @@ class Client(Methods): os.remove(file.name) return None + except asyncio.CancelledError: + if not in_memory: + file.close() + os.remove(file.name) + + raise asyncio.CancelledError() else: if in_memory: file.name = file_name