在 python (bsddb) 中使用 Berkeley Db 时出现 DEADLOCK_WRAP 错误
我正在使用 berkdb 来存储大量键值对,但由于某种原因,当我稍后尝试访问某些数据时,我收到此错误:
try:
key = 'scrape011201-590652'
contenttext = contentdict[key]
except:
print the error
<type 'exceptions.KeyError'> 'scrape011201-590652' in
contenttext = contentdict[key]\n', ' File "/usr/lib64/python2.5/bsddb/__init__.py",
line 223, in __getitem__\n return _DeadlockWrap(lambda: self.db[key]) #
self.db[key]\n', 'File "/usr/lib64/python2.5/bsddb/dbutils.py", line 62, in
DeadlockWrap\n return function(*_args, **_kwargs)\n', ' File
"/usr/lib64/python2.5/bsddb/__init__.py", line 223, in <lambda>\n return
_DeadlockWrap(lambda: self.db[key]) # self.db[key]\n']
我不确定 DeadlockWrap 是什么,但没有任何其他程序或进程访问berkdb 或写入它(据我所知),所以不确定我们如何会陷入僵局,如果它指的是这一点。我是否有可能尝试快速访问数据?我在循环中调用了这个函数,所以像
for i in hugelist:
#try to get a value from the berkdb
#do something with it
我在多个数据集上运行这个函数一样,这个错误只发生在其中一个(最大的一个)上,而不是其他数据集上。
I am using a berkdb to store a huge list of key-value pairs but for some reason when i try to access some of the data later i get this error:
try:
key = 'scrape011201-590652'
contenttext = contentdict[key]
except:
print the error
<type 'exceptions.KeyError'> 'scrape011201-590652' in
contenttext = contentdict[key]\n', ' File "/usr/lib64/python2.5/bsddb/__init__.py",
line 223, in __getitem__\n return _DeadlockWrap(lambda: self.db[key]) #
self.db[key]\n', 'File "/usr/lib64/python2.5/bsddb/dbutils.py", line 62, in
DeadlockWrap\n return function(*_args, **_kwargs)\n', ' File
"/usr/lib64/python2.5/bsddb/__init__.py", line 223, in <lambda>\n return
_DeadlockWrap(lambda: self.db[key]) # self.db[key]\n']
I am not sure what DeadlockWrap is but there isnt any other program or process accessing the berkdb or writing to it (as far as i know,) so not sure how we could get a deadlock, if its referring to that. Is it possible that I am trying to access the data to rapidly? I have this function call in a loop, so something like
for i in hugelist:
#try to get a value from the berkdb
#do something with it
I am running this with multiple datasets and this error only occurs with one of them, the largest one, not the others.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常确定
DeadlockWrap
内容与此无关。这只是自动提供带有后退策略的重试的一种方法。换句话说,如果数据库操作失败,它会等待一段时间,然后重试多次,然后最终失败。您似乎从字典
get
操作中收到KeyError
,这更可能是由于您使用的密钥实际上并不存在于数据库。尝试使用类似以下内容的代码:
这应该会显示表中是否不存在该记录(通过输出
Urk!
消息)。至于在这种情况下你要做什么,这取决于你的架构。您可能希望返回None
或空字符串。您可能还想做您现在正在做的事情(引发异常)。I'm pretty certain the
DeadlockWrap
stuff is not relevant here. It's simply a way to automagically provide retries with a back-off strategy. In other words, if the database manipulation fails, it waits a little bit then tries again, a number of times before finally failing.You seem to be getting a
KeyError
from your dictionaryget
operation which is more likely to be due to the fact that the key you're using doesn't actually exist in the database.Try your code with something like:
This should show you if the record doesn't exist in the table (by outputting the
Urk!
message). As to what you do in that case, it depends on your architecture. You would probably want to return eitherNone
or an empty string. You may also want to do exactly what you're doing now (raising an exception).