From 9ac36140d355b18af38c1c28d7821fb87b4ad9ca Mon Sep 17 00:00:00 2001 From: vinoyang Date: Thu, 24 Oct 2024 11:13:35 +0800 Subject: [PATCH] Remove unnecessary close when download file (#233) --- tosfs/core.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tosfs/core.py b/tosfs/core.py index 270b22f..cba9e51 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -1017,20 +1017,8 @@ def download_file() -> None: body, content_length = self._open_remote_file( bucket, key, version_id, range_start=0, **kwargs ) - try: - with open(lpath, "wb") as f: - retryable_func_executor(_read_chunks, args=(body, f)) - finally: - try: - body.close() - except Exception as e: - logger.error( - "Failed to close the body when calling " - "get_file from %s to %s: %s", - rpath, - lpath, - e, - ) + with open(lpath, "wb") as f: + retryable_func_executor(_read_chunks, args=(body, f)) retryable_func_executor(download_file)