@@ -79,19 +79,21 @@ def close(self):
79
79
"""
80
80
Close the connector and release resources.
81
81
"""
82
- if self ._hook_dir :
83
- self ._hook_dir = ''
82
+ try :
83
+ if self ._hook_dir :
84
+ self ._hook_dir = ''
84
85
85
- if builtins .open == self ._connector_open :
86
- builtins .open = self ._origin_open
87
- torch .UntypedStorage .from_file = self ._origin_from_file
86
+ if builtins .open == self ._connector_open :
87
+ builtins .open = self ._origin_open
88
88
89
- if torch .UntypedStorage .from_file == self ._from_file_helper :
90
- torch .UntypedStorage .from_file = self ._origin_from_file
89
+ if torch .UntypedStorage .from_file == self ._from_file_helper :
90
+ torch .UntypedStorage .from_file = self ._origin_from_file
91
91
92
- if self ._real_connector is not None :
93
- del self ._real_connector
94
- self ._real_connector = None
92
+ if self ._real_connector is not None :
93
+ del self ._real_connector
94
+ self ._real_connector = None
95
+ except :
96
+ print ("exception in close, ignore" )
95
97
96
98
def open (self , uri , binary = True ):
97
99
"""
@@ -116,8 +118,7 @@ def _from_file_helper(self, filename, shared, nbytes):
116
118
def _connector_open (self , file , mode = 'r' , buffering = - 1 , encoding = None , errors = None , newline = None , closefd = True , opener = None ):
117
119
if isinstance (file , pathlib .Path ):
118
120
file = str (file )
119
-
120
- if self ._hook_dir and isinstance (file , str ) and file .startswith (self ._hook_dir ):
121
+ if self ._hook_dir and file .startswith (self ._hook_dir ):
121
122
binary = False
122
123
if 'b' in mode :
123
124
binary = True
0 commit comments