创建连接时 pymongo 挂起
当我从 Python shell 运行以下几行时,代码挂起:
from pymongo import Connection
c = Connection('localhost', 27017)
我猜它正在等待来自 mongo 服务器的回复。当我中断呼叫时,我得到回溯:
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 325, in __init__
self.__find_node()
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 589, in __find_node
node = self.__try_node(candidate)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 528, in __try_node
response = self.admin.command("ismaster")
File "/usr/local/lib/python2.6/dist-packages/pymongo/database.py", line 335, in command
_is_command=True)
File "/usr/local/lib/python2.6/dist-packages/pymongo/collection.py", line 486, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 655, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 618, in _refresh
self.__query_spec(), self.__fields))
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 575, in __send_message
**kwargs)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 807, in _send_message_with_response
return self.__send_and_receive(message, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 788, in __send_and_receive
return self.__receive_message_on_socket(1, request_id, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 774, in __receive_message_on_socket
header = self.__receive_data_on_socket(16, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 763, in __receive_data_on_socket
chunk = sock.recv(length - len(message))
KeyboardInterrupt
mongod 选择不响应吗?看来我一直在等待从套接字接收数据。
然而,这是有效的(这意味着 mongod 运行正常):
$ mongo --port 27017
MongoDB shell version: 2.0.1
connecting to: 127.0.0.1:27017/test
When I run the following lines from Python shell, the code hangs:
from pymongo import Connection
c = Connection('localhost', 27017)
I guess it's waiting to hear back from the mongo server. When I interrupt the call, I get the traceback:
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 325, in __init__
self.__find_node()
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 589, in __find_node
node = self.__try_node(candidate)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 528, in __try_node
response = self.admin.command("ismaster")
File "/usr/local/lib/python2.6/dist-packages/pymongo/database.py", line 335, in command
_is_command=True)
File "/usr/local/lib/python2.6/dist-packages/pymongo/collection.py", line 486, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 655, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 618, in _refresh
self.__query_spec(), self.__fields))
File "/usr/local/lib/python2.6/dist-packages/pymongo/cursor.py", line 575, in __send_message
**kwargs)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 807, in _send_message_with_response
return self.__send_and_receive(message, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 788, in __send_and_receive
return self.__receive_message_on_socket(1, request_id, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 774, in __receive_message_on_socket
header = self.__receive_data_on_socket(16, sock)
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 763, in __receive_data_on_socket
chunk = sock.recv(length - len(message))
KeyboardInterrupt
Is mongod choosing not to respond? It looks like I'm stuck waiting to receive data from the socket.
However, this works (which means mongod is running properly):
$ mongo --port 27017
MongoDB shell version: 2.0.1
connecting to: 127.0.0.1:27017/test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉愚蠢的错误。我在后台停止了 mongod 工作。
Sorry dumb mistake. I had the mongod job stopped in the background.