jrsm
jrsm

Reputation: 1695

How to start a pyro server on a remote pc?

I am looking for a possibility to do something like this:

import paramiko, Pyro4

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('machine1', username='user1')

stdin,stdout,stderr = ssh.exec_command("python server.py")
uri = stdout.readlines()[-1]
ssh.close()
worker = Pyro4.Proxy(uri)
worker.do_some_stuff()


# server.py
import Pyro4

class Worker(object):
    def do_some_stuff(): 
         ....


worker = Worker()

daemon=Pyro4.Daemon()                
uri=daemon.register(worker) 
daemon.requestLoop()  
print uri

So i want to log into a machine start a PyroServer / Daemon and return the uri over ssh. After this step i want to execute a function on the remote object. Unfortunately if I start a Pyroserver it doesn't run in the background so I don't get any return value from stdout. What would be the best way to do this ? I am pretty new to the pyro library so maybe there is some more elegant way to this, thank you.

Upvotes: 2

Views: 1416

Answers (2)

abhijitjaiswal
abhijitjaiswal

Reputation: 139

I would suggest to have a name server running and register a predefined uri with the name server which won't make you wait for the uri, something like follows:

starting name server:

python -m Pyro4.naming -n machine1_ip

now in the server.py, include following lines:

daemon=Pyro4.Daemon(machine1_ip)
worker=Worker()
uri=daemon.register(worker)
ns.register("worker_uri", uri)

Now you can access using "worker_uri" uri:

test=Pyro4.Proxy("PYRONAME:worker_uri")
test.do_some_stuff()

Hope this helps.

Upvotes: 0

Irmen de Jong
Irmen de Jong

Reputation: 2847

Print the daemon's uri before calling requestLoop(). The latter, as the name shows, enters a loop. It normally does not return from it unless receiving a break signal.

Upvotes: 0

Related Questions