【问题标题】:Pymongo AssertionError: ids don't matchPymongo AssertionError:ID 不匹配
【发布时间】:2011-06-16 14:08:26
【问题描述】:

我用:

  • MongoDB 1.6.5
  • Pymongo 1.9
  • Python 2.6.6

我有 3 种类型的守护进程。第一次从网络加载数据,第二次分析并保存结果,第三组结果。他们都在使用 Mongodb。 有时第三个守护进程会抛出许多这样的异常(主要是当数据库中有大量数据时):

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/gevent-0.13.1-py2.6-linux-x86_64.egg/gevent/greenlet.py", line 405, in run
    result = self._run(*self.args, **self.kwargs)
  File "/data/www/spider/daemon/scripts/mainconverter.py", line 72, in work
    for item in res:
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/cursor.py", line 601, in next
    if len(self.__data) or self._refresh():
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/cursor.py", line 564, in _refresh
    self.__query_spec(), self.__fields))
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/cursor.py", line 521, in __send_message
    **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/connection.py", line 743, in _send_message_with_response
    return self.__send_and_receive(message, sock)
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/connection.py", line 724, in __send_and_receive
    return self.__receive_message_on_socket(1, request_id, sock)
  File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9_-py2.6-linux-x86_64.egg/pymongo/connection.py", line 714, in __receive_message_on_socket
    struct.unpack("<i", header[8:12])[0])
AssertionError: ids don't match -561338340 0
<Greenlet at 0x2baa628: <bound method Worker.work of <scripts.mainconverter.Worker object at 0x2ba8450>>> failed with AssertionError

谁能告诉这个异常的原因以及如何解决这个问题。

谢谢。

【问题讨论】:

标签: python mongodb pymongo


【解决方案1】:

这可能是与您如何将工作线程与 gevent 协程一起使用的线程问题。看起来 pymongo 连接对象正在读取它未发出的请求的响应。

【讨论】:

  • 你完全正确。我发现一些连接在光标完成输出之前返回到池中。
  • 那么,有什么解决办法呢?我有同样的问题,可以解决。
猜你喜欢
  • 1970-01-01
  • 2017-06-18
  • 2016-11-10
  • 2022-12-23
  • 2021-12-04
  • 2022-01-25
  • 2020-07-27
  • 1970-01-01
  • 2021-10-07
相关资源
最近更新 更多