Skip to content

Commit 231909e

Browse files
fix: ensure file handles are properly closed (#1483)
* fix: ensure file handles are properly closed Fixed resource leaks in two files where file handles were not properly closed --------- Co-authored-by: taovinci0 <taovinci0@users.noreply.github.com> Co-authored-by: Charles Frye <charles@modal.com>
1 parent 9d696c6 commit 231909e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

06_gpu_and_ml/speech-to-text/asr_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import math
77
import os
8+
from pathlib import Path
89
import sys
910
import tempfile
1011
import wave
@@ -82,7 +83,7 @@ def get_bytes_from_wav(location: str) -> bytes:
8283
if location.startswith("http"):
8384
bytes = urlopen(location).read()
8485
else:
85-
bytes = open(location, "rb").read()
86+
bytes = Path(location).read_bytes()
8687

8788
return bytes
8889

07_web_endpoints/fasthtml-checkboxes/fasthtml_checkboxes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
db = modal.Dict.from_name("example-fasthtml-checkboxes-db", create_if_missing=True)
3131

3232
css_path_local = Path(__file__).parent / "styles.css"
33-
css_path_remote = "/assets/styles.css"
33+
css_path_remote = Path("/assets/styles.css")
3434

3535

3636
@app.function(
@@ -76,7 +76,7 @@ async def on_shutdown():
7676
db["checkboxes"] = checkboxes
7777
print("Checkbox state persisted.")
7878

79-
style = open(css_path_remote, "r").read()
79+
style = css_path_remote.read_text()
8080
app, _ = fh.fast_app(
8181
# FastHTML uses the ASGI spec, which allows handling of shutdown events
8282
on_shutdown=[on_shutdown],

0 commit comments

Comments
 (0)