我在我的 python 程序中使用 PyRo。我有一个问题。B 类:在 callFromProxy 中打印 0,但在 callfun 中打印正确值 = 10。为什么?怎么修?
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