From cadd7231919327a768f0f0d672c1b31bf8b9812e Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Sun, 8 Oct 2023 10:27:25 -0300 Subject: [PATCH] Cancel other image task when one already finished on tg frontend ipfs image gather --- skynet/frontend/telegram/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/skynet/frontend/telegram/__init__.py b/skynet/frontend/telegram/__init__.py index ea26b69..550633c 100644 --- a/skynet/frontend/telegram/__init__.py +++ b/skynet/frontend/telegram/__init__.py @@ -266,10 +266,15 @@ class SkynetTelegramFrontend: logging.warning(f'couldn\'t get ipfs binary data at {link}!') tasks = [ - get_and_set_results(ipfs_link), - get_and_set_results(ipfs_link_legacy) + asyncio.create_task(get_and_set_results(ipfs_link)), + asyncio.create_task(get_and_set_results(ipfs_link_legacy)) ] - await asyncio.gather(*tasks) + done, pending = await asyncio.wait( + tasks, return_when=asyncio.FIRST_COMPLETED) + + for task in pending: + task.cancel() + png_img = None if ipfs_link_legacy in results: png_img = results[ipfs_link_legacy]