From 6f6c5e9f5e1e9a18c949a5a7b1b28702b5b05d85 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Fri, 17 Dec 2021 11:56:24 +0200 Subject: [PATCH] Fix Storage Helper rename partial file throwing errors on multiple access --- clearml/storage/helper.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/clearml/storage/helper.py b/clearml/storage/helper.py index 8e54495b..f71bc9ee 100644 --- a/clearml/storage/helper.py +++ b/clearml/storage/helper.py @@ -711,7 +711,20 @@ class StorageHelper(object): pass # rename temp file to local_file - os.rename(temp_local_path, local_path) + # noinspection PyBroadException + try: + os.rename(temp_local_path, local_path) + except Exception: + # noinspection PyBroadException + try: + os.unlink(temp_local_path) + except Exception: + pass + # file was downloaded by a parallel process, check we have the final output and delete the partial copy + path_local_path = Path(local_path) + if not path_local_path.is_file() or path_local_path.stat().st_size <= 0: + raise Exception('Failed renaming partial file, downloaded file exists and a 0-sized file') + # report download if we are on the second chunk if verbose or download_reported: self._log.info(