Python 多处理:远程连接到管理器时套接字错误超时

发布于 2024-10-28 00:45:02 字数 1222 浏览 4 评论 0原文

新人,第一次提问。
我正在使用 Python 的多处理模块,该模块当前正在我的本地主机上创建一个管理器和几个(45)个进程。 我的管理器设置如下:

manager = QueueManager(address=('', 50000), authkey='abracadabra')
manager.get_server().serve_forever()

我还想在另一台计算机上远程创建一些其他客户端进程。所以,假设我的 IP 是 abcd,远程计算机中客户端的管理器设置如下:(

manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.connect()

是的,它是从文档中复制粘贴的)。
但是,我运行服务器并且本地主机中的所有 45 个进程都正常,然后我运行远程客户端并得到以下信息:

Traceback (most recent call last):
  File "govmap-parallel-crawler-client.py", line 144, in <module>
    manager.connect()
  File "/usr/lib/python2.6/multiprocessing/managers.py", line 474, in connect
    conn = Client(self._address, authkey=self._authkey)
  File "/usr/lib/python2.6/multiprocessing/connection.py", line 134, in Client
    c = SocketClient(address)
  File "/usr/lib/python2.6/multiprocessing/connection.py", line 252, in SocketClient
    s.connect(address)
  File "<string>", line 1, in connect
socket.error: [Errno 110] Connection timed out

两台计算机都可以毫无问题地互相 ping 和 ssh。
我的猜测:中间有一个(或两个!)防火墙使得连接不可能。这是正确的吗?
如果是:有没有办法使用安全的已知端口来避开防火墙,或者可能是更礼貌的解决方案?
如果不是:发生了什么?
谢谢!!

newcomer and first ever question here.
I am using the multiprocessing module of Python which is currently creating a Manager and a couple (45) processes on my localhost.
My Manager is set up as following:

manager = QueueManager(address=('', 50000), authkey='abracadabra')
manager.get_server().serve_forever()

I want also to create some other client processes remotely on another computer. So, let's say my IP is a.b.c.d, the Manager of the client in the remote computer is set up as following:

manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.connect()

(yes, it's copy-pasted from the documentation).
However, I run the server and all 45 processes in localhost are fine, then I run the remote client and I get this:

Traceback (most recent call last):
  File "govmap-parallel-crawler-client.py", line 144, in <module>
    manager.connect()
  File "/usr/lib/python2.6/multiprocessing/managers.py", line 474, in connect
    conn = Client(self._address, authkey=self._authkey)
  File "/usr/lib/python2.6/multiprocessing/connection.py", line 134, in Client
    c = SocketClient(address)
  File "/usr/lib/python2.6/multiprocessing/connection.py", line 252, in SocketClient
    s.connect(address)
  File "<string>", line 1, in connect
socket.error: [Errno 110] Connection timed out

Both computers can ping and ssh each other without problems.
My guess: there is one (or two!) firewall in between making the connection impossible. Is this correct?
If yes: is there a way to use a safe known port in order to avoid the firewall or maybe a more polite solution?
If no: what is happening?
Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

庆幸我还是我 2024-11-04 00:45:02

使用 ssh 隧道进行互连?例如在客户端上:

ssh abcd -L12345:localhost:50000

如果客户端连接到本地主机端口 12345,则应该通过隧道连接到 abcd 端口 50000。

编辑:当然,使用 SSH 隧道可能不是生产环境中的最佳解决方案,但至少它可以让你消除其他问题。

Use an ssh tunnel for interconnect? E.g on client:

ssh a.b.c.d -L12345:localhost:50000

If the client connects to localhost port 12345, it should be tunnelled to a.b.c.d port 50000.

EDIT: Of course, using an SSH tunnel might not be the best solution in a production environment, but at least it lets you eliminate other issues.

对不⑦ 2024-11-04 00:45:02

根据您的代码片段的定义,服务器仅侦听本地主机(127.0.0.1)而不是(abcd),因此您无法从远程客户端连接。

为此,请使用:

manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.get_server().serve_forever()

As defined by your snippet the server listens only on localhost (127.0.0.1) and not (a.b.c.d) thus you cannot connect from remote client.

To do so use:

manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.get_server().serve_forever()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文