创建连接时 pymongo 挂起

发布于 2024-12-13 13:41:30 字数 2128 浏览 0 评论 0原文

当我从 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 技术交流群。

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

发布评论

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

评论(1

尘世孤行 2024-12-20 13:41:31

抱歉愚蠢的错误。我在后台停止了 mongod 工作。

Sorry dumb mistake. I had the mongod job stopped in the background.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文