下面是测试这个问题的示例代码。当调用testmaster.test() (这是服务器远程对象的方法)(实际上这里不确定它是服务器还是客户端)时,执行就会永远停止。
即使@ Pyro4 .回调也没有帮助(不确定在这里是否合乎逻辑)我正在使用Python2.7.12和Pyro4如何解决这个问题,任何帮助都将不胜感激
#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()发布于 2017-02-26 20:11:21
您必须在单独的进程中运行守护进程。这就是Pyro的目的:在其他进程中调用方法!
在与代码的其余部分相同的进程中运行它是没有意义的:那么,为什么要使用Pyro呢?您没有将对象分布在不同的进程或机器上。
您的代码“挂起”的原因是因为testmaster.test()调用试图连接到Pyro守护进程,但它还没有在任何地方运行。因此它将挂起(直到套接字超时)。永远不会到达daemon.requestLoop() --但是,即使是这样,代码也是错误的:在同一个程序中运行守护进程和通过Pyro调用对象是没有意义的。
我建议至少阅读手册中的介绍,以掌握基本知识:http://pythonhosted.org/Pyro4/intro.html#simple-example
https://stackoverflow.com/questions/42464376
复制相似问题