0

我对 RPC 和 Pyro 完全陌生,并试图理解它的概念。我正在做它的网站示例,当我做 ns=True 时我的代码不起作用,尽管它在 ns=False.I 时工作'收到此错误:

Pyro4.errors.NamingError:无法找到名称服务器

当我使用 ipdb 进行调试时,我看到:

CommunicationError:无法连接:[Errno 111] 连接被拒绝

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()

不启动守护进程的解决方案是什么?

4

2 回答 2

0

ns=Truein 参数将serveSimple在某处正在运行的名称服务器中注册对象。你必须自己开始。如果没有名称服务器已经在运行,它将无法工作。

于 2015-04-01T22:40:26.723 回答
0

您需要仔细阅读教程中的说明。您需要在warehouse.py之外运行python -m Pyro4.naming

于 2015-06-17T03:05:43.153 回答