From 0d9e639f4facbd69eb353aa01893bc7d8ac4b2e3 Mon Sep 17 00:00:00 2001 From: Lonami Date: Thu, 4 Jul 2019 15:34:51 +0200 Subject: [PATCH] Support asynchronous progress_callback's --- telethon/client/downloads.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telethon/client/downloads.py b/telethon/client/downloads.py index 10e22781..bb129724 100644 --- a/telethon/client/downloads.py +++ b/telethon/client/downloads.py @@ -3,6 +3,7 @@ import io import os import pathlib import typing +import inspect from .. import utils, helpers, errors, hints from ..requestiter import RequestIter @@ -434,7 +435,9 @@ class DownloadMethods: input_location, request_size=part_size, dc_id=dc_id): f.write(chunk) if progress_callback: - progress_callback(f.tell(), file_size) + r = progress_callback(f.tell(), file_size) + if inspect.isawaitable(r): + await r f.flush() if in_memory: