From fd8f80c8b880dd7c284c109ca7f03dbe978bc532 Mon Sep 17 00:00:00 2001 From: Paul Harter Date: Tue, 6 Dec 2022 17:07:19 +0000 Subject: [PATCH] Explicitly closing model file after reading it (#630) --- whisper/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/whisper/__init__.py b/whisper/__init__.py index ba3ea13..f80fe72 100644 --- a/whisper/__init__.py +++ b/whisper/__init__.py @@ -39,7 +39,8 @@ def _download(url: str, root: str, in_memory: bool) -> Union[bytes, str]: raise RuntimeError(f"{download_target} exists and is not a regular file") if os.path.isfile(download_target): - model_bytes = open(download_target, "rb").read() + with open(download_target, "rb") as f: + model_bytes = f.read() if hashlib.sha256(model_bytes).hexdigest() == expected_sha256: return model_bytes if in_memory else download_target else: