From b7e65d9c9c0e8e0e323ca4acbd14cb92e64037c1 Mon Sep 17 00:00:00 2001 From: jaskaranSM Date: Sat, 19 Oct 2019 16:44:26 +0530 Subject: [PATCH] Changed sleep() call for Fixing Delay. - Also Tweaked Torrent Metadata Status Logic a bit. --- .gitignore | 3 ++- bot/helper/mirror_utils/download_tools.py | 11 +++++------ bot/modules/cancel_mirror.py | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 04bfd67..b865fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ data* .idea *.json *.pickle -authorized_chats.txt \ No newline at end of file +authorized_chats.txt +log.txt diff --git a/bot/helper/mirror_utils/download_tools.py b/bot/helper/mirror_utils/download_tools.py index 237d87f..14b35f2 100644 --- a/bot/helper/mirror_utils/download_tools.py +++ b/bot/helper/mirror_utils/download_tools.py @@ -41,23 +41,22 @@ class DownloadHelper: should_update = True if self.__is_torrent: # Waiting for the actual gid - new_gid = None - while new_gid is None: - download = self.__get_download() + download = self.__get_download() + while download.is_complete != True: # Check every few seconds + download = self.__get_download() if download.has_failed: self.__listener.onDownloadError(download.error_message, status_list, index) return if download.is_paused: self.__listener.onDownloadError("Download cancelled manually by user", status_list, index) return - sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) if should_update: try: self.__listener.onDownloadProgress(get_download_status_list(), index) except KillThreadException: should_update = False - # Check every few seconds - new_gid = self.__get_followed_download_gid() + sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) + new_gid = self.__get_followed_download_gid() with download_dict_lock: download_dict[self.__listener.message.message_id] = DownloadStatus(new_gid, self.__listener.message.message_id) diff --git a/bot/modules/cancel_mirror.py b/bot/modules/cancel_mirror.py index 3ae0367..62c505c 100644 --- a/bot/modules/cancel_mirror.py +++ b/bot/modules/cancel_mirror.py @@ -4,6 +4,7 @@ from bot import download_dict, aria2, dispatcher, download_dict_lock, DOWNLOAD_D from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.ext_utils.fs_utils import clean_download from bot.helper.telegram_helper.bot_commands import BotCommands +from time import sleep @run_async def cancel_mirror(update: Update, context): @@ -28,6 +29,7 @@ def cancel_mirror(update: Update, context): upload_helper = download_dict[mirror_message.message_id].upload_helper if upload_helper is not None: upload_helper.cancel() + sleep(1) #Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/') @@ -35,7 +37,7 @@ def cancel_mirror(update: Update, context): def cancel_all(update, context): aria2.pause_all(True) sendMessage('Cancelled all downloads!', context, update) - + sleep(1) #Wait a Second For Aria2 To free Resources. clean_download(DOWNLOAD_DIR)