file kept open in utils pickled resource, fixed
This commit is contained in:
parent
244d1045ce
commit
7f39f4df66
|
@ -228,12 +228,14 @@ def pickled_resource(pickle_path:str, generation_func:callable, *args):
|
||||||
return generation_func(*args)
|
return generation_func(*args)
|
||||||
else:
|
else:
|
||||||
if os.path.exists(pickle_path):
|
if os.path.exists(pickle_path):
|
||||||
return pickle.load(open(pickle_path, 'rb'))
|
with open(pickle_path, 'rb') as fin:
|
||||||
|
instance = pickle.load(fin)
|
||||||
else:
|
else:
|
||||||
instance = generation_func(*args)
|
instance = generation_func(*args)
|
||||||
os.makedirs(str(Path(pickle_path).parent), exist_ok=True)
|
os.makedirs(str(Path(pickle_path).parent), exist_ok=True)
|
||||||
pickle.dump(instance, open(pickle_path, 'wb'), pickle.HIGHEST_PROTOCOL)
|
with open(pickle_path, 'wb') as foo:
|
||||||
return instance
|
pickle.dump(instance, foo, pickle.HIGHEST_PROTOCOL)
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
def _check_sample_size(sample_size):
|
def _check_sample_size(sample_size):
|
||||||
|
|
Loading…
Reference in New Issue