Downloader: Cleanup on exception

Otherwise a file exists error will show up if any exception happens
but cancel.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-04-30 23:26:22 -04:00
parent e4084b15c1
commit ae75db1829

View file

@ -171,7 +171,7 @@ async def hf_repo_download(
logger.info(f"Finished download for {repo_id}")
return download_path
except asyncio.CancelledError:
except (asyncio.CancelledError, Exception) as exc:
# Cleanup on cancel
if download_path.is_dir():
shutil.rmtree(download_path)
@ -180,3 +180,7 @@ async def hf_repo_download(
# Stop the progress bar
progress.stop()
# Re-raise exception if the task isn't cancelled
if not isinstance(exc, asyncio.CancelledError):
raise exc