Skip to content

Commit 023c746

Browse files
authored
fix: closed file descriptior issue (#5162)
* fix: closed file descriptior issue Signed-off-by: Frost Ming <me@frostming.com> * fix: add local bentoml requirement if non-url dep is present Signed-off-by: Frost Ming <me@frostming.com>
1 parent af9d664 commit 023c746

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/bentoml/_internal/bento/build_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,16 @@ def write_to_bento(
604604
option_line.options.pop("requirements", None)
605605

606606
if any(
607-
req.name and req.name.lower() == "bentoml"
607+
req.name and req.name.lower() == "bentoml" and req.link is not None
608608
for req in requirements_txt.requirements
609609
):
610610
has_bentoml_req = True
611611

612612
f.write(requirements_txt.dumps(preserve_one_empty_line=True))
613613
elif self.packages is not None:
614-
bentoml_req_regex = re.compile(r"^bentoml\b(?![-\._])", re.IGNORECASE)
614+
bentoml_req_regex = re.compile(
615+
r"^bentoml(?:\[[^\]]+\])?\s*@", re.IGNORECASE
616+
)
615617
if any(bentoml_req_regex.match(pkg) for pkg in self.packages):
616618
has_bentoml_req = True
617619
f.write("\n".join(self.packages) + "\n")

src/bentoml/_internal/cloud/bento.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ def io_cb(x: int):
212212
fd, tar_name = mkstemp(
213213
prefix="bentoml-bento-", suffix=".tar", dir=bentoml_tmp_dir
214214
)
215+
tar_io = os.fdopen(fd, "wb+")
215216
try:
216-
tar_io = os.fdopen(fd, "wb+")
217217
with self.spinner.spin(
218218
text=f'Creating tar archive for bento "{bento.tag}"..'
219219
):
@@ -403,7 +403,7 @@ def chunk_upload(
403403
self.spinner.log(f'[bold green]Successfully pushed Bento "{bento.tag}"')
404404
finally:
405405
try:
406-
os.close(fd)
406+
tar_io.close()
407407
except OSError:
408408
pass
409409
os.unlink(tar_name)

src/bentoml/_internal/cloud/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def io_cb(x: int):
158158
fd, tar_name = mkstemp(
159159
prefix="bentoml-model-", suffix=".tar", dir=bentoml_tmp_dir
160160
)
161+
tar_io = os.fdopen(fd, "wb+")
161162
try:
162-
tar_io = os.fdopen(fd, "wb+")
163163
with self.spinner.spin(
164164
text=f'Creating tar archive for model "{model.tag}"..'
165165
):
@@ -342,7 +342,7 @@ def chunk_upload(
342342
self.spinner.log(f'[bold green]Successfully pushed model "{model.tag}"')
343343
finally:
344344
try:
345-
os.close(fd)
345+
tar_io.close()
346346
except OSError:
347347
pass
348348
os.unlink(tar_name)

0 commit comments

Comments
 (0)