Serialization of return value (2)

Bořek Patzák <[email protected]> Thu, 23 Oct 2014 22:55:20 +0200
Newsgroups gmane.comp.python.pyro
Message-ID <[email protected]>
Hello,
I have encountered a strange problem with return value from remote 
class, when using pickle protocol.
When type of return value is a class, then depending whether it is 
derived from object base or not, the return value is different.
I have python 2.7.6 and Pyro version 4.28 installed.
Note: I have  attached wrong listing in previous post, with subject 
"Serialization of return value", so this is fixed one and I am sorry for 
the mistake.

To illustrate this, consider following example:

--------------   file A.py -------------------
class A(object):
     def __init__(self,id=0):
         self.id = id

     def msg(self):
         return "hello, this is a"

-------------- file server.py ---------------
import Pyro4
Pyro4.config.SERIALIZER="pickle"
Pyro4.config.SERIALIZERS_ACCEPTED={'pickle'}
import A

ns = Pyro4.locateNS('127.0.0.1', port=9090)
daemon = Pyro4.Daemon(host='127.0.0.1', port=9091)

class Server(object):
     def __init__(self):
         self.a = A.A(2)
         self.a_uri=None
     def getA(self):
         return self.a
     def getAURI(self):
         if self.a_uri == None:
             self.a_uri = daemon.register(self.a)
         return self.a_uri


server = Server()
uri    = daemon.register(server)
ns.register('Demo.server', uri)

daemon.requestLoop()

-----------------file client.py ------------------
import Pyro4
Pyro4.config.SERIALIZER="pickle"
Pyro4.config.SERIALIZERS_ACCEPTED={'pickle'}
import A

ns = Pyro4.locateNS('localhost', port=9090)
uri = ns.lookup('Demo.server')
print "Uri:", uri
server = Pyro4.Proxy(uri)
print "Server:",server
a = server.getAURI()
print "a:", a
b= server.getA()
print "b:", b

print "finished"

--------------------end--------------------------

When I run a client, the following response is received:
$ python client.py
Uri: PYRO:obj_58a48bb0def74534b8749c6b10d3fa8b-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091
Server: <Pyro4.core.Proxy at 0x7f1592605510, not connected, for 
PYRO:obj_58a48bb0def74534b8749c6b10d3fa8b-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091>
a: PYRO:obj_140031e8eb8f4eaf881a2922b49738c5-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091
b: <Pyro4.core.Proxy at 0x7f1592605610, not connected, for 
PYRO:obj_140031e8eb8f4eaf881a2922b49738c5-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091>
finished

So if I got it right a is Pyro URI, but b is URI as well, even though I 
would expect that a local copy to be created on return.
However, when I change the definition of A omitting object as a base:

-------file A.py----------------
class A:
     def __init__(self,id=0):
         self.id = id

     def msg(self):
         return "hello, this is a"
-----------end----------------------
Ahter restarting the server script,  I got the following:

$python client.py
Uri: PYRO:obj_7c82d0bc804048e4b9f5f84265db03ea-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091
Server: <Pyro4.core.Proxy at 0x7fb7efca3510, not connected, for 
PYRO:obj_7c82d0bc804048e4b9f5f84265db03ea-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091>
a: PYRO:obj_1a35acfa7fc74d56894434ad56091b29-savSHZN5Fh8qMp+WYRx65w@public.gmane.org:9091
b: <A.A instance at 0x7fb7efc9dfc8>
finished

This is what I would expect, even in the original code. My questions are:
1) is this intended behaviour?
2) for classes derived from object base, can the the type of return 
value (local copy instead of URI) changed?

Thank you,
Borek


------------------------------------------------------------------------------