From de060c7d17e7cd8ae92c7530ebfa2331bade7e6c Mon Sep 17 00:00:00 2001 From: Carson Rochon Date: Tue, 23 Sep 2025 20:51:40 -0600 Subject: [PATCH] Update __init__.py Using "with" to close file immediately after reading instead of leaving it open for garbage collector --- whisper/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/whisper/__init__.py b/whisper/__init__.py index f284ec0..e2b5fa1 100644 --- a/whisper/__init__.py +++ b/whisper/__init__.py @@ -86,7 +86,8 @@ def _download(url: str, root: str, in_memory: bool) -> Union[bytes, str]: output.write(buffer) loop.update(len(buffer)) - 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: raise RuntimeError( "Model has been downloaded but the SHA256 checksum does not not match. Please retry loading the model."