pyro proxy method returns class instance

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue May 6 12:23:50 EDT 2003


I am trying to use a pyro proxy instance to call a method that returns
an instance of a user defined class

    import Pyro.core
    from Pyro.errors import PyroError

    class SomeClass(Pyro.core.ObjBase):
        def __init__(self):
            Pyro.core.ObjBase.__init__(self)

        def speak(self):
            return  'hi'


    class MyProxy(Pyro.core.ObjBase):
        def __init__(self):
            Pyro.core.ObjBase.__init__(self)

        def get_some(self):
            return SomeClass()

    Pyro.core.initServer()
    daemon = Pyro.core.Daemon(host='localhost', port=2358)
    daemon.connect(MyProxy(), 'MyProxy')
    daemon.connect(SomeClass(), 'SomeClass')
    daemon.requestLoop()


And my client looks like

    import sys
    import Pyro.core

    Pyro.core.initClient()
    hostname = 'localhost'
    port = '2358'
    URI = 'PYROLOC://'+hostname+':'+port+'/MyProxy'

    a = Pyro.core.getProxyForURI(URI)
    o = a.get_some()
    print o.speak()


But the client call o = a.get_some() fails with 

  AttributeError: 'module' object has no attribute 'SomeClass'

Could someone give me advice or point me to an example that shows how
to do this?

Thanks.
John Hunter

Pyro 3.2





More information about the Python-list mailing list