在 python (bsddb) 中使用 Berkeley Db 时出现 DEADLOCK_WRAP 错误

发布于 2024-08-28 06:10:52 字数 980 浏览 10 评论 0 原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(2

倾城花音 2024-09-04 06:10:52

我非常确定 DeadlockWrap 内容与此无关。这只是自动提供带有后退策略的重试的一种方法。换句话说,如果数据库操作失败,它会等待一段时间,然后重试多次,然后最终失败。

您似乎从字典 get 操作中收到 KeyError ,这更可能是由于您使用的密钥实际上并不存在于数据库。

尝试使用类似以下内容的代码:

try:
    key = 'scrape011201-590652'
    if not contentdict.has_key(key):
        print "Urk!, No record for %s"%(key)
    contenttext = contentdict[key]
except:
    print the error

这应该会显示表中是否不存在该记录(通过输出 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 dictionary get 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:

try:
    key = 'scrape011201-590652'
    if not contentdict.has_key(key):
        print "Urk!, No record for %s"%(key)
    contenttext = contentdict[key]
except:
    print the error

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 either None or an empty string. You may also want to do exactly what you're doing now (raising an exception).

空城缀染半城烟沙 2024-09-04 06:10:52
contenttext = contentdict[key] if contentdict.has_key(key) else None
contenttext = contentdict[key] if contentdict.has_key(key) else None
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文