我在我的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发布于 2010-02-14 22:41:00
我相信(如果我错了,请纠正我) PyRo使用异步调用,至少在默认情况下。
因此,当您调用callFromProxy时,printvalue可能会在itemB上的callfun之前执行,因为调用A.callfun和B.callfun需要一些时间。如果发生这种情况,当第一次调用printvalue时,elements["name"]仍为0。
https://stackoverflow.com/questions/2261317
复制相似问题