Pyro and class init() with another class instance

Daniel Krause <m.daniel.krause-gM/[email protected]>
Newsgroups gmane.comp.python.pyro
Message-ID <CAMiLiKg9uqhnTP++QPmVtfEb1QUgimih2fzRpx2KSTxWcXnT3Q@mail.gmail.com>
Hello,

I am new to Pyro, and I feel I need some advice.
With one of my first test scripts I run into problems when I try to use a
method of an class object from inside another class.
a.method() works
b.a.method() is not working

Maybe my point is better to understand with some code. Here is a test case:

##############
#1
#starting the name server in a shell with
#python -m Pyro4.naming

##############################
#2
#test script for server
'''
pyrotest_server
'''
import Pyro4

class TestA():
    def __init__(self):
        #just a variable var
        self.var = 123
    def get_var(self):
        return self.var

class TestB():
    def __init__(self, instance_TestA):
        #object b of type TestA
        self.b_a = instance_TestA

if __name__ == '__main__':
    server_a = TestA()
    server_b = TestB(server_a)
    daemon=Pyro4.Daemon()           # make a Pyro daemon
    ns=Pyro4.locateNS()             # find the name server
    uri=daemon.register(server_a)   # register as a Pyro object
    ns.register("server_a", uri)    # register the object with a name in
the name server
    print 'server_a registered'
    uri=daemon.register(server_b)   # register as a Pyro object
    ns.register("server_b", uri)    # register the object with a name in
the name server
    print 'server_b registered'
    print "Ready."
    daemon.requestLoop()

##########################
#3
#starting the server test script
##########################
#4
#shell output
C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py:155:
UserWarnin
g: HMAC_KEY not set, protocol data may not be secure
  warnings.warn("HMAC_KEY not set, protocol data may not be secure")
server_a registered
server_b registered
Ready.

###########################
#5
#client test script
'''
pyrotest_client.py
'''
import Pyro4

if __name__ == '__main__':
    client_a = Pyro4.Proxy("PYRONAME:server_a")
    print "client_a:", client_a
    print "client_a.var = ",client_a.var
    print "client_a.getA() = ",client_a.get_var()
    client_b = Pyro4.Proxy("PYRONAME:server_b")
    print "client_b:", client_b
    print "client_b.b_a = ",client_b.b_a
    print "client_b.b_a.var = ",client_b.b_a.var
    print "client_b.b_a.get_var() = ",client_b.b_a.get_var()

#############################
#6
#starting client test script
#############################
#7
#shell output
C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py:155:
UserWarnin
g: HMAC_KEY not set, protocol data may not be secure
  warnings.warn("HMAC_KEY not set, protocol data may not be secure")
client_a: <Pyro4.core.Proxy at 0x250f3c8, not connected, for
PYRONAME:server_a>
client_a.var =  <Pyro4.core._RemoteMethod object at 0x0000000002A4B3C8>
client_a.getA() =  123
client_b: <Pyro4.core.Proxy at 0x2a4b3c8, not connected, for
PYRONAME:server_b>
client_b.b_a =  <Pyro4.core._RemoteMethod object at 0x0000000002A4B438>
client_b.b_a.var =  <Pyro4.core._RemoteMethod object at 0x0000000002A4B470>
client_b.b_a.get_var() =
Traceback (most recent call last):
  File "C:\Users\mdk\workspace\src\pyrotest_client.py", lin
e 15, in <module>
    print "client_b.b_a.get_var() = ",client_b.b_a.get_var()
  File "C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py",
line
149, in __call__
    return self.__send(self.__name, args, kwargs)
  File "C:\Python27\lib\site-packages\pyro4-4.17-py2.7.egg\Pyro4\core.py",
line
294, in _pyroInvoke
    raise data
AttributeError: TestB instance has no attribute 'b_a.get_var'



Any help is welcome.
Daniel

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb

_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.