0

I use PyRo in my python programm. And I have a problem. class B: In callFromProxy print 0, but in callfun print right value = 10. Why? How to fix?

class A(Pyro.core.ObjBase):
 # set link to item class B
 def set(self, real_B):
  self.item_B = real_B

 # call function callfun in item_B
 def callfun(self):
  self.item_B.callfun(10)

class B(Pyro.core.ObjBase):
 # init class B
 def __init__(self):
  self.elements = {"name":0}

 # set proxy to item class A
 def set(self, proxyA):
  self.proxyA = proxyA

 # print
 def printvalue(self):
  print self.elements["name"]

 # call from proxy
 def callFromProxy(self):
  self.proxyA.callfun()
  self.printvalue() # this is not print 10, print 0

 # call function
 def callfun(self, value):
  self.elements["name"] = value
  self.printvalue() # but this is print 10

itemA = A()

# proxyA connect from PyRo to itemA

itemB = B()
itemB.set(itemA)

itemA.set(itemB)

itemB.callFromProxy() # this is not print 10
Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
gimlis
  • 11
  • 1
  • I fixed a few lines that I assumed were typos in your code. – Can Berk Güder Feb 14 '10 at 14:30
  • 2
    I just tested the code above using the latest Pyro version and it works exactly as a I expected - it prints 10 twice. If I understand your post, this what you want. – Justin Peel Feb 14 '10 at 16:02
  • Hi. I'm totally not sure what were you trying to do here, but if I understand you right - you set itemA to a proxy object, and itemB is left intact, i.e. it is a regular instance of class B right? If it is, then what happens in your code, is that basically you make a copy of an object itemB references to, send it to server, modify it on server, and then print out the state of another object, which was originally created on client side, and which is not changed. – Tim Jul 21 '11 at 19:17

1 Answers1

1

I believe (and correct me if I'm wrong) PyRo uses asynchronous calls, at least by default.

So when you call callFromProxy, printvalue might get executed before callfun on itemB, because it takes time to call A.callfun and B.callfun. If/when this happens, elements["name"] will still be 0 when printvalue is called for the first time.

Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137