Re: : capability to use @property for remote object
Andreas Kostyrka <[email protected]> Tue, 5 Nov 2013 15:09:17 +0100
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <CAMWQy6bdZ31pPZq4xfkgj2U+i4roFho=dgW-Lt5iL4LrR+aw0w@mail.gmail.com> |
Short answer: I don't think so. Happy to learn something else. Long answer: it's a hard problem, far from trivial. Basically, when you write obj.method() in Python, you are doing multiple things: # that fetches the method and makes it into a bound method that knows that it's first parameter is obj _ = obj.method # now call the thing. _() Now how does the proxy object work? (that's just an educated guestimate, I didn't look at the source) # fetch a RemoteCall object that knows what it's supposed to call _ = proxy.method # and now do the network traffic thing: _() The biggie here is that at the time you do the attribute lookup, we don't know what the user will want to do with it. Now the reality is that it's kind of solvable if you are willing to add additional latency and/or some complexity to the code. Ideas for a solution would include: 1.) trigger an attribute access remotely the same time you do it locally. If the result is callable, return the RemoteMethod instance. If it's not, try to serialize the value and send it back. Disadvantages include doubled network latency. 2.) when creating the proxy, scan the remote object to see what descriptors are defined for the class. That should give at least sensible hints what attribute names need special care (see item 1) without causing additional latency for normal method calls. The basic problem here is that method 2 breaks down if the remote object defines custom __getattr__ (e.g. as the Proxy class does). Anyway, the big issues are: * knowing what is meant to be called and what is meant to be a value. Probably the best condition for that I can think of would be is it serialize-able, e.g. methods will not be serialize-able, hence you can return a RemoteMethod proxy method. * dynamically created attributes. Basically when the remote object defines __getattr__/__getattribute__ any ideas of optimizing the attribute lookup remotely away goes out of the window. So, it's a hard problem, as in there are no perfect solutions. In practice, you need to find a solution strategy that is appropriate to your use case. Andreas 2013/11/5 Andrii Pavlyk <[email protected]> > Hello, > > > > Could you, please, help me to resolve issue I encountered trying to use > Pyro? > > > > I perform the following code > > on server: > > > > import Pyro4 > > > > class CTestClassWProperty(object): > > > > def __init__(self): > > super().__init__() > > > > self.__test_property = "Value to check" > > > > @property > > def test_property(self): > > return self.__test_property > > > > def print_test_property(self): > > print("The test property is '{}'".format(self.test_property)) > > return self.test_property > > > > if __name__ == '__main__': > > class_w_property=CTestClassWProperty() > > daemon=Pyro4.Daemon() > > uri=daemon.register(class_w_property) > > print("Ready. Object uri = {}".format(uri)) > > daemon.requestLoop() > > > > on client: > > > > import Pyro4 > > > > uri=input("What is the Pyro uri of the class with property object? > ").strip() > > > > class_w_property=Pyro4.Proxy(uri) > > print(class_w_property.test_property) > > print(class_w_property.print_test_property()) > > > > The output of client code is below: > > > > <Pyro4.core._RemoteMethod object at 0x0000000002AB1128> > > Value to check > > > > So, as you can see, when get the CTestClassWProperty @property with no > Pyro there is its value printed out. > > When get the @property for Pyro object of the corresponding class there is > _RemoteMethod object printed out instead of this property’s value. > > > > Therefore question is > > How to use @property of classes via their Pyro object with no any changes > in remote class? > > > > > > Thanks for your help. > > > > > ------------------------------------------------------------------------------ > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. > Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and > register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > _______________________________________________ > Pyro-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/pyro-core > > ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk _______________________________________________ Pyro-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyro-core