开发者

PyRo and python

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.callfu开发者_开发技巧n(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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜