From 4f7d8f3d601206d32adab5a93c81656d6f58e99f Mon Sep 17 00:00:00 2001 From: painor <30215770+painor@users.noreply.github.com> Date: Mon, 19 Aug 2019 18:42:43 +0100 Subject: [PATCH] Add async support to upload file prgoress callback This will make it possible to use async callbacks when uploading a file. --- telethon/client/uploads.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index ed5ad343..deae48f7 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -573,7 +573,9 @@ class UploadMethods: self._log[__name__].debug('Uploaded %d/%d', part_index + 1, part_count) if progress_callback: - progress_callback(stream.tell(), file_size) + r = progress_callback(f.tell(), file_size) + if inspect.isawaitable(r): + await r else: raise RuntimeError( 'Failed to upload file part {}.'.format(part_index))