2

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.

jrsm
  • 1,595
  • 2
  • 18
  • 39

2 Answers2

0

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.

Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26
0

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.

abhijitjaiswal
  • 139
  • 1
  • 8