ecmwf / climetlab

Python package for easy access to weather and climate data
Apache License 2.0
374 stars 58 forks source link

set cache not working if never cached #18

Closed aaronspring closed 3 years ago

aaronspring commented 3 years ago

After upgrading to the new 0.7 climetlab, set("cache-directory", path) does not work anymore. EDIT: maybe this has nothing to do with the new climetlab, but rather if nothing has been cached yet. At least when nothing has been cached in the past.

Is that on purpose or if not, could you please add a small note to the documentation? https://climetlab.readthedocs.io/en/latest/reference/settings.html

import climetlab
# no caching before ever
cml.settings.set("cache-directory", ".")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-557cbc31a23e> in <module>
      1 # caching path for climetlab
      2 #cache_path = "/work/mh0727/m300524/S2S_AI/cache" # set your own path
----> 3 cml.settings.set("cache-directory", ".")

/opt/conda/lib/python3.8/site-packages/climetlab/core/settings.py in set(self, name, *args, **kwargs)
    134 
    135         self._settings[name] = value
--> 136         self._changed()
    137 
    138     def reset(self, name: str = None):

/opt/conda/lib/python3.8/site-packages/climetlab/core/settings.py in _changed(self)
    168         self._save()
    169         for cb in self._callbacks:
--> 170             cb()
    171 
    172     def on_change(self, callback: Callable[[], None]):

/opt/conda/lib/python3.8/site-packages/climetlab/decorators.py in wrapped(*args, **kwargs)
     35     def wrapped(*args, **kwargs):
     36         with LOCK:
---> 37             return func(*args, **kwargs)
     38 
     39     return wrapped

/opt/conda/lib/python3.8/site-packages/climetlab/core/caching.py in settings_changed()
     62 def settings_changed():
     63     global _connection
---> 64     if _connection.db is not None:
     65         _connection.db.close()
     66     _connection.db = None

AttributeError: '_thread._local' object has no attribute 'db'

import climetlab_s2s_ai_challenge
print(f'Climetlab version : {cml.__version__}')
print(f'Climetlab-s2s-ai-challenge plugin version : {climetlab_s2s_ai_challenge.__version__}')
Climetlab version : 0.7.0
Climetlab-s2s-ai-challenge plugin version : 0.6.2
floriankrb commented 3 years ago

Thanks, this is fixed with v0.7.2 (released today).

aaronspring commented 3 years ago

Thanks for fixing