I also think it’s either shelve or the underlying dbm module.
I just replaced shelve with dbm.dumb and at least the writes seem to work now.
I wanted to try dbm.gnu as this would be an ideal replacement, but trying to import it throws an error; probalby something is missing in the Docker container:
2016-10-19 14:17:38.043684 WARNING ------------------------------------------------------------
2016-10-19 14:17:38.044004 WARNING Unexpected error during loading of switch_reset.py:
2016-10-19 14:17:38.044179 WARNING ------------------------------------------------------------
2016-10-19 14:17:38.066928 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/appdaemon/appdaemon.py", line 665, in readApp
importlib.reload(conf.modules[module_name])
File "/usr/local/lib/python3.5/importlib/__init__.py", line 166, in reload
_bootstrap._exec(spec, module)
File "<frozen importlib._bootstrap>", line 626, in _exec
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/conf/.apps/switch_reset.py", line 3, in <module>
import dbm.gnu
File "/usr/local/lib/python3.5/dbm/gnu.py", line 3, in <module>
from _gdbm import *
ImportError: No module named '_gdbm'
I need to look into this.
Anyhow, there’s now an error appaerently because the data inside the db is not serialized objects:
2016-10-19 14:27:22.066047 WARNING ------------------------------------------------------------
2016-10-19 14:27:22.069560 WARNING Unexpected error:
2016-10-19 14:27:22.072037 WARNING ------------------------------------------------------------
2016-10-19 14:27:22.137853 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/appdaemon/appdaemon.py", line 418, in worker
function(ha.sanitize_timer_kwargs(args["kwargs"]))
File "/conf/.apps/switch_reset.py", line 60, in set_switches
new_state = self.set_state(entity, state = self.device_db[entity])
File "/usr/local/lib/python3.5/site-packages/appdaemon/appapi.py", line 164, in set_state
r = requests.post(apiurl, headers=headers, json=args, verify = conf.certpath)
File "/usr/local/lib/python3.5/site-packages/requests/api.py", line 110, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 461, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 394, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python3.5/site-packages/requests/models.py", line 297, in prepare
self.prepare_body(data, files, json)
File "/usr/local/lib/python3.5/site-packages/requests/models.py", line 428, in prepare_body
body = complexjson.dumps(json)
File "/usr/local/lib/python3.5/json/__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "/usr/local/lib/python3.5/json/encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/lib/python3.5/json/encoder.py", line 256, in iterencode
return _iterencode(o, 0)
File "/usr/local/lib/python3.5/json/encoder.py", line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'16.0' is not JSON serializable
But I think we’re on the right path…
Still wondering why shelve behaves this way, even when “upgrading” from a python 3.4 docker image to 3.5.
Sebastian