Quickly now, how does it work? A scenario
- The programmer writes a module 'test' containing a class 'testclass', which will be accessed remotely.
- The server creates one or more instances of the 'testclass', and registers them with the Pyro Naming Service.
- The client queries the Naming Service for the location of those objects. It gets a Pyro URI for them.
- The client asks Pyro to create proxies for the remote object URIs.
- As the proxy appears just like the real 'testclass', the client can now invoke methods on the remote objects, as if it were normal (local) objects.
Minimal example code: the Server
import Pyro.core
import Pyro.naming
class JokeGen(Pyro.core.ObjBase):
def joke(self, name):
return "Sorry "+name+", I don't know any jokes."
daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
uri=daemon.connect(JokeGen(),"jokegen")
daemon.requestLoop()
Minimal example code: the Client
import Pyro.core
# finds object automatically if you're running the Name Server.
jokes = Pyro.core.getProxyForURI("PYRONAME://jokegen")
print jokes.joke("Irmen")
If you don't like having to start a Name Server... or want to know more...
Then you are lucky because Pyro provides a direct-lookup feature. And in the Example chapter in the manual, a lot more is explained.
- Python Remote Objects 