简体   繁体   English

连接到 Multiprocessing BaseManager 在本地工作,但不适用于远程服务器

[英]Connecting to Multiprocessing BaseManager works locally but not for remote server

I'm currently using themultiprocessing.managers.BaseManager functionality to serve some Python objects so that I could interact with their proxies on the client side.我目前正在使用multiprocessing.managers.BaseManager功能来提供一些 Python 对象,以便我可以在客户端与它们的代理进行交互。

After I start the server defined by the BaseManager, I try to connect at the client side to access the serveables.启动 BaseManager 定义的服务器后,我尝试在客户端连接以访问可服务对象。 However, I'm seeing an EoFError only when the server and client exist on different hosts.但是,只有当服务器和客户端存在于不同的主机上时,我才会看到EoFError If they were on the same local host, I can get access just fine.如果他们在同一个本地主机上,我可以很好地访问。

server.py服务器.py

from multiprocessing.managers import BaseManager
password = "password".encode("utf-8")

class MyManager(BaseManager):
    pass

a = {'one': 1}  # to be served
MyManager.register("get_a", callable=lambda: a)
m = MyManager(address=("127.0.0.1", 60000), authkey=password)
m.start()
# ... long running process ...

client.py客户端.py

from multiprocessing.managers import BaseManager
password = "password".encode("utf-8")

class MyManager(BaseManager):
    pass

MyManager.register("get_a")
manager = MyManager(address=("SERVER_IP", 60000), authkey=password)
manager.connect()  # raises EoFError

Traceback:追溯:

File "client.py", line 20, in connect_to_executor_manager
               manager.connect()
File "/usr/lib/python3.7/multiprocessing/managers.py", line 512, in connect
              conn = Client(self._address, authkey=self._authkey)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 498, in Client
            answer_challenge(c, authkey)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 741, in answer_challenge
              message = connection.recv_bytes(256)         # reject large message
File "/usr/lib/python3.7/multiprocessing/connection.py", line 216, in recv_bytes
            buf = self._recv_bytes(maxlength)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 407, in _recv_bytes
          buf = self._recv(4)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 383, in _recv
          raise EOFError

I just ran into the same problem, but luckily, I created a clue when I modified my code in the course of debugging我刚刚遇到了同样的问题,但幸运的是,我在调试过程中修改代码时创造了一个线索

from multiprocessing.managers import BaseManager
password = "password".encode("utf-8")

class MyManager(BaseManager):
    pass

a = {'one': 1}  # to be served
MyManager.register("get_a", callable=lambda: a)
m = MyManager(address=("127.0.0.1", 60000), authkey=password)
print(f"serving at address {m.address}")      # I added the equivalent of this line
m.start()

My test code caused the "serving at address..." line to print twice.我的测试代码导致“在地址服务...”行打印两次。 This made me think that the code was getting spawned twice.这让我觉得代码被生成了两次。 I recall seeing somewhere that the server code should be contained in an if __name__ ==... block, so I tried that and things started working.我记得在某处看到服务器代码应该包含在if __name__ ==...块中,所以我尝试了,事情开始工作了。
I'm no expert, but I think this error is caused during the spawn/forking/etc.我不是专家,但我认为这个错误是在产卵/分叉/等过程中引起的。 process.过程。 Long story short, you can modify your server.py code like so and it will likely work.长话短说,您可以像这样修改您的server.py代码,它可能会起作用。

from multiprocessing.managers import BaseManager
password = "password".encode("utf-8")

class MyManager(BaseManager):
    pass

a = {'one': 1}  # to be served
MyManager.register("get_a", callable=lambda: a)

if __name__ == '__main__':
    m = MyManager(address=("127.0.0.1", 60000), authkey=password)
    m.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 停止 Python 多处理 BaseManager 'serve_forever' 服务器? - Stopping a Python Multiprocessing BaseManager 'serve_forever' server? 使用Python多处理管理器(BaseManager / SyncManager)与远程计算机共享队列时断管 - Broken Pipe when Using Python Multiprocessing Managers (BaseManager/SyncManager) to Share Queue with Remote Machines 日志在本地工作,但不在远程工作 - Logging works locally but not on remote multiprocessing.BaseManager何时使用RemoteError? - When does multiprocessing.BaseManager use RemoteError? 多处理BaseManager shutdown()需要二十秒 - Multiprocessing BaseManager shutdown() takes twenty-seconds 连接到PyPy3多处理远程管理器时出错 - Error connecting to PyPy3 multiprocessing remote manager Flask 在本地工作,但不在服务器上? - Flask works locally, but not on a server? 多处理远程服务器和套接字错误 - Multiprocessing Remote Server and Socket Errors 我可以使用多处理 BaseManager 动态注册对象以进行代理吗? - Can I dynamically register objects to proxy with a multiprocessing BaseManager? unittest,在本地工作,但不在远程服务器上,没有名为 x.__main__ 的模块; 'x' 是 package,不能直接执行 - unittest, works locally, but not on a remote server, no module named x.__main__; 'x' is a package and cannot be directly executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM