首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用Pyro4远程对象的方法。

调用Pyro4远程对象的方法。
EN

Stack Overflow用户
提问于 2017-02-26 03:21:31
回答 1查看 726关注 0票数 0

下面是测试这个问题的示例代码。当调用testmaster.test() (这是服务器远程对象的方法)(实际上这里不确定它是服务器还是客户端)时,执行就会永远停止。

即使@ Pyro4 .回调也没有帮助(不确定在这里是否合乎逻辑)我正在使用Python2.7.12和Pyro4如何解决这个问题,任何帮助都将不胜感激

代码语言:javascript
复制
#Run python -m Pyro4.naming in another terminal first:
import Pyro4

@Pyro4.expose
@Pyro4.callback
class Master:
    @Pyro4.expose
    @Pyro4.callback
    def test(self):
        print "this is test"

nameserver = Pyro4.locateNS('localhost', 9090)
deamon = Pyro4.Daemon()
uri = deamon.register(Master())
nameserver.register("Master", uri, safe=True)
testmaster=Pyro4.Proxy(uri)#Object of master to call some functions from it
print "before calling test" #this will be executed
testmaster.test()
print "after calling test" #but not this, it just stuck forever- how can I make it to be executed
deamon.requestLoop()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-26 20:11:21

您必须在单独的进程中运行守护进程。这就是Pyro的目的:在其他进程中调用方法!

在与代码的其余部分相同的进程中运行它是没有意义的:那么,为什么要使用Pyro呢?您没有将对象分布在不同的进程或机器上。

您的代码“挂起”的原因是因为testmaster.test()调用试图连接到Pyro守护进程,但它还没有在任何地方运行。因此它将挂起(直到套接字超时)。永远不会到达daemon.requestLoop() --但是,即使是这样,代码也是错误的:在同一个程序中运行守护进程和通过Pyro调用对象是没有意义的。

我建议至少阅读手册中的介绍,以掌握基本知识:http://pythonhosted.org/Pyro4/intro.html#simple-example

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42464376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档