python搁置dbm.error?

python搁置dbm.error?,第1张

概述我正在尝试将一个dicts字典添加到搁置文件中: >>> d = shelve.open('index.shelve')>>> d<shelve.DbfilenameShelf object at 0x21965f0>>>> print(list(d.keys()))[]>>> d['index'] = indexTraceback (most recent call last): 我正在尝试将一个dicts字典添加到搁置文件中:

>>> d = shelve.open('index.shelve')>>> d<shelve.DbfilenameShelf object at 0x21965f0>>>> print(List(d.keys()))[]>>> d['index'] = indexTraceback (most recent call last):  file "<stdin>",line 1,in <module>  file "/bns/rma/local/python/lib/python3.1/shelve.py",line 124,in __setitem__    self.dict[key.encode(self.keyenCoding)] = f.getvalue()_dbm.error: cannot add item to database

索引有点大但不是很大.它本质上是一个浮点数组:

>>> len(index)219>>> a = [ index[k][k1] for k in index for k1 in index[k] ]>>> len(a)59995>>> all([ type(x) is float for x in a ])True

这个错误是什么?此外,是否在模块或模块文档中的某处我应该寻找有关错误代表的更多信息?错误信息不是很有用,至少对我来说:).

解决方法 我实际上遇到了与dbm模块相同的问题,它在我的代码库中可以重现,但我无法在隔离测试中重现它.

我的印象是,有一个锁可以防止在读取数据库时写入.在我的情况下,db是〜200Kb,有~10个键并且插入time.sleep(1)可以解决问题,暗示在db [key] =值时某些异步进程没有完成.

总结

以上是内存溢出为你收集整理的python搁置dbm.error?全部内容,希望文章能够帮你解决python搁置dbm.error?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1196444.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-03
下一篇2022-06-03

发表评论

登录后才能评论

评论列表(0条)

    保存