0

Below is the example code to test this problem that I have. The execution just stuck forever when calling testmaster.test() which is a method of the server remote object (actually not sure here it is server or client).

Even @Pyro4.callback doesn't help either (not sure if it is logical to be here) I am using Python 2.7.12 and Pyro4 How can I solve this problem, any help will be appreciated

#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()
Khalid
  • 13
  • 3

1 Answers1

0

You have to run the daemon in a separate process. That's whats Pyro is meant for: to call methods in other processes!

Running it in the same process as the rest of your code makes no sense: why would you use Pyro at all then? You're not distributing your objects over different processes or machines.

The reason your code 'hangs' is because the testmaster.test() call is trying to connect to a Pyro daemon but that is not running anywhere yet. So it will hang (until the socket times out). The daemon.requestLoop() is never reached - but still, even if it was, the code is wrong: it makes little sense to run a daemon and call objects via Pyro in the same program.

I suggest reading the introduction in the manual at least to grasp the basics: http://pythonhosted.org/Pyro4/intro.html#simple-example

Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26
  • Thanks Irmen, The code was a simple form example of the problem I had. Yeah I solved it by calling the method via object itself (not remote object). – Khalid Feb 27 '17 at 04:43
  • but new problem I am coping now. I am developing Echo algorithm where one python file executed multiple times, and all these processes become one node of the algorithm (the first object/process which executed becomes bootstrap that has information about all nodes and initiating the distributed message) the bootstrap has a while loop(within calls remote objects of other nodes) to send dist msg to nodes upon receiving acks. Other node is calling this loop function which make the node not to reach its daemon.requestloop() call. if I swap these two statements then i can't call loop function. – Khalid Feb 27 '17 at 05:00
  • Your code structure is wrong then. You're not properly separating client and server logic. – Irmen de Jong Feb 27 '17 at 18:37