Pymongo AssertionError:ids不匹配

时间:2011-01-27 14:16:25

标签: python mongodb pymongo

我用:

  • MongoDB 1.6.5
  • Pymongo 1.9
  • Python 2.6.6

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

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

任何人都可以说明导致此异常的原因以及如何解决此问题。

感谢。

1 个答案:

答案 0 :(得分:4)

这可能是与如何使用gevent协同工作线程相关的线程问题。似乎pymongo连接对象正在读取它没有做出的请求的响应。