Skip to content

Commit

Permalink
Merge pull request #27 from yuchen0cc/main
Browse files Browse the repository at this point in the history
catch exception in close
  • Loading branch information
liulanzheng authored Jan 16, 2025
2 parents c4ba14e + ee90f23 commit 10e1ff1
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions oss-model-connector/ossmodelconnector/oss_model_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ def close(self):
"""
Close the connector and release resources.
"""
if self._hook_dir:
self._hook_dir = ''
try:
if self._hook_dir:
self._hook_dir = ''

if builtins.open == self._connector_open:
builtins.open = self._origin_open
torch.UntypedStorage.from_file = self._origin_from_file
if builtins.open == self._connector_open:
builtins.open = self._origin_open

if torch.UntypedStorage.from_file == self._from_file_helper:
torch.UntypedStorage.from_file = self._origin_from_file
if torch.UntypedStorage.from_file == self._from_file_helper:
torch.UntypedStorage.from_file = self._origin_from_file

if self._real_connector is not None:
del self._real_connector
self._real_connector = None
if self._real_connector is not None:
del self._real_connector
self._real_connector = None
except:
print("exception in close, ignore")

def open(self, uri, binary = True):
"""
Expand All @@ -116,8 +118,7 @@ def _from_file_helper(self, filename, shared, nbytes):
def _connector_open(self, file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None):
if isinstance(file, pathlib.Path):
file = str(file)

if self._hook_dir and isinstance(file, str) and file.startswith(self._hook_dir):
if self._hook_dir and file.startswith(self._hook_dir):
binary = False
if 'b' in mode:
binary = True
Expand Down

0 comments on commit 10e1ff1

Please sign in to comment.