我对RPC和Pyro完全陌生,并试图理解它的含义。我正在做它的网站示例,当我做ns=True时,我的代码就不起作用了,尽管ns=False时它仍然有效。我得到了这个错误:
Pyro4.errors.NamingError: Failed to locate the nameserver
当我使用ipdb调试时:
CommunicationError: cannot connect: [Errno 111] Connection refused
from __future__ import print_function
import Pyro4
import person
class Warehouse(object):
def __init__(self):
self.contents = ["chair", "bike", "flashlight", "laptop", "couch"]
def list_contents(self):
return self.contents
def take(self, name, item):
self.contents.remove(item)
print("{0} took the {1}.".format(name, item))
def store(self, name, item):
self.contents.append(item)
print("{0} stored the {1}.".format(name, item))
def main():
warehouse = Warehouse()
Pyro4.Daemon.serveSimple(
{
warehouse: "example.warehouse"
},
ns = True)
if __name__=="__main__":
main()
不启动守护程序的解决方案是什么?在
你需要仔细阅读教程上的说明。 您需要在仓库.py在
serveSimple
中的ns=True
参数将在某处运行的名称服务器中注册对象。你得自己动手。如果没有名称服务器正在运行,它将无法工作。在相关问题 更多 >
编程相关推荐