Skip to content

Commit

Permalink
fix: closed file descriptior issue (#5162)
Browse files Browse the repository at this point in the history
* fix: closed file descriptior issue

Signed-off-by: Frost Ming <[email protected]>

* fix: add local bentoml requirement if non-url dep is present

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Dec 27, 2024
1 parent af9d664 commit 023c746
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,16 @@ def write_to_bento(
option_line.options.pop("requirements", None)

if any(
req.name and req.name.lower() == "bentoml"
req.name and req.name.lower() == "bentoml" and req.link is not None
for req in requirements_txt.requirements
):
has_bentoml_req = True

f.write(requirements_txt.dumps(preserve_one_empty_line=True))
elif self.packages is not None:
bentoml_req_regex = re.compile(r"^bentoml\b(?![-\._])", re.IGNORECASE)
bentoml_req_regex = re.compile(
r"^bentoml(?:\[[^\]]+\])?\s*@", re.IGNORECASE
)
if any(bentoml_req_regex.match(pkg) for pkg in self.packages):
has_bentoml_req = True
f.write("\n".join(self.packages) + "\n")
Expand Down
4 changes: 2 additions & 2 deletions src/bentoml/_internal/cloud/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def io_cb(x: int):
fd, tar_name = mkstemp(
prefix="bentoml-bento-", suffix=".tar", dir=bentoml_tmp_dir
)
tar_io = os.fdopen(fd, "wb+")
try:
tar_io = os.fdopen(fd, "wb+")
with self.spinner.spin(
text=f'Creating tar archive for bento "{bento.tag}"..'
):
Expand Down Expand Up @@ -403,7 +403,7 @@ def chunk_upload(
self.spinner.log(f'[bold green]Successfully pushed Bento "{bento.tag}"')
finally:
try:
os.close(fd)
tar_io.close()
except OSError:
pass
os.unlink(tar_name)
Expand Down
4 changes: 2 additions & 2 deletions src/bentoml/_internal/cloud/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def io_cb(x: int):
fd, tar_name = mkstemp(
prefix="bentoml-model-", suffix=".tar", dir=bentoml_tmp_dir
)
tar_io = os.fdopen(fd, "wb+")
try:
tar_io = os.fdopen(fd, "wb+")
with self.spinner.spin(
text=f'Creating tar archive for model "{model.tag}"..'
):
Expand Down Expand Up @@ -342,7 +342,7 @@ def chunk_upload(
self.spinner.log(f'[bold green]Successfully pushed model "{model.tag}"')
finally:
try:
os.close(fd)
tar_io.close()
except OSError:
pass
os.unlink(tar_name)
Expand Down

0 comments on commit 023c746

Please sign in to comment.