From cfb5d6a53227aa8a48c242eb1b0b0434f4a49009 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Thu, 19 Sep 2024 20:06:53 +0900 Subject: [PATCH] also download to a tmp file not the live file to avoid compounding errors from network failure --- model_filemanager/download_models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model_filemanager/download_models.py b/model_filemanager/download_models.py index 23a52c441..c2d0c6f93 100644 --- a/model_filemanager/download_models.py +++ b/model_filemanager/download_models.py @@ -158,7 +158,10 @@ async def track_download_progress(response: aiohttp.ClientResponse, await progress_callback(model_name, status) last_update_time = time.time() - with open(file_path, 'wb') as f: + if os.path.exists(file_path + '.tmp'): + os.remove(file_path + '.tmp') + + with open(file_path + '.tmp', 'wb') as f: chunk_iterator = response.content.iter_chunked(8192) while True: try: @@ -171,6 +174,8 @@ async def track_download_progress(response: aiohttp.ClientResponse, if time.time() - last_update_time >= interval: await update_progress() + os.rename(file_path + '.tmp', file_path) + await update_progress() logging.info(f"Successfully downloaded {model_name}. Total downloaded: {downloaded}")