python 搁置 dbm.error?

发布于 2024-10-17 11:53:25 字数 811 浏览 5 评论 0原文

我正在尝试将字典的字典添加到搁置文件中:

>>> d = shelve.open('index.shelve')
>>> d
<shelve.DbfilenameShelf object at 0x21965f0>
>>> print(list(d.keys()))
[]
>>> d['index'] = index
Traceback (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

这个错误是什么?另外,模块或模块文档中是否有某个地方我应该寻找有关错误代表的更多信息?错误消息的信息量不是很大,至少对我来说是这样:)。

I'm trying to add a dict of dicts to a shelve file:

>>> d = shelve.open('index.shelve')
>>> d
<shelve.DbfilenameShelf object at 0x21965f0>
>>> print(list(d.keys()))
[]
>>> d['index'] = index
Traceback (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

index is somewhat large but not huge. It is essentially an array of floats:

>>> 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

What is this error? Also, is there somewhere within the module or the module docs I should be looking to get more info on what the error represents? The error message is not very informative, at least to me :).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-10-24 11:53:25

实际上,我对 dbm 模块也有同样的问题,它在我的代码库中是可重现的,但我无法在单独的测试中重现它。

我的印象是,有一个锁可以防止在读取数据库时写入。就我而言,数据库约为 200Kb,有约 10 个键,插入 time.sleep(1) 可以解决问题,暗示某些异步过程在 时刻尚未完成db[键] = 值

I actually had the same problem with the dbm module, it is reproducable in my codebase but I can't reproduce it in an isolated test.

My impression is that there is a lock that prevents writing when the database is being read. In my case, the db is ~200Kb, with ~10 keys and inserting a time.sleep(1) would solve the problem, hinting at some async process not finished at the moment of the db[key] = value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文