You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The load_obj in the pickle_utils.py file makes lots of use of this pattern: dill.load(open(os.path.join(dir_name, file), 'rb'))
And since dill does not close the file handler passed to the load method, it causes a Resource Warning for each of the parts of the model being loaded. In the following case, it caused 2856 of those warnings flooding the logs.
We were using graykite 0.2.0, but I see the issue is still present in version 0.4.0.
If instead we had a simple read_pickle or dill_load function that would handle closing the file:
def read_pickle(path, mode):
"""Loads the pickled files and closes the file handle.
Parameters
----------
path : `str`
The path to the pickled file.
mode : `str`
The mode of the open function.
"""
with open(path, mode) as file:
data = dill.load(file)
return data
It would be just a question of changing the calls to dill.load(open(...)) to read_pickle(...). Are there any reason not to use this pattern?
The text was updated successfully, but these errors were encountered:
briantani
changed the title
ResrouceWarning: Unclosed file... messages when deserializing a model.
ResourceWarning: Unclosed file... messages when deserializing a model.
Aug 22, 2022
The load_obj in the pickle_utils.py file makes lots of use of this pattern:
dill.load(open(os.path.join(dir_name, file), 'rb'))
And since dill does not close the file handler passed to the
load
method, it causes a Resource Warning for each of the parts of the model being loaded. In the following case, it caused 2856 of those warnings flooding the logs.We were using graykite 0.2.0, but I see the issue is still present in version 0.4.0.
If instead we had a simple
read_pickle
ordill_load
function that would handle closing the file:It would be just a question of changing the calls to
dill.load(open(...))
toread_pickle(...)
. Are there any reason not to use this pattern?The text was updated successfully, but these errors were encountered: