连接到多处理BaseManager在本地工作,但不适合远程服务器
我目前正在使用“ nofollow noreferrer”> supertrocessing.managers.basemanager.basemanager.basemanager.basemanager 服务功能一些Python对象,以便我可以在客户端与他们的代理进行互动。
启动由BaseManager定义的服务器后,我尝试在客户端连接以访问Serveables。但是,仅当服务器和客户端存在在不同的主机上时,我才会看到eoferror
。如果他们在同一本地主机上,我可以访问良好。
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)
m = MyManager(address=("127.0.0.1", 60000), authkey=password)
m.start()
# ... long running process ...
client.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
trackback:
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'm currently using the multiprocessing.managers.BaseManager functionality to serve some Python objects so that I could interact with their proxies on the client side.
After I start the server defined by the BaseManager, I try to connect at the client side to access the serveables. However, I'm seeing an EoFError
only when the server and client exist on different hosts. If they were on the same local host, I can get access just fine.
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)
m = MyManager(address=("127.0.0.1", 60000), authkey=password)
m.start()
# ... long running process ...
client.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是遇到了同样的问题,但是幸运的是,在调试测试代码的过程中修改代码时,我创建了一个线索,
这导致“在地址上服务...”行打印两次。这使我认为代码被催生了两次。我记得在某个地方看到服务器代码应包含在
中,如果__name __ == ...
block,所以我尝试了一下,事情开始工作。我不是专家,但是我认为此错误是在产卵/分叉/等期间引起的。过程。长话短说,您可以像这样修改
server.py
代码,它可能会起作用。I just ran into the same problem, but luckily, I created a clue when I modified my code in the course of debugging
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.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.