通过Pyro传输对象

时间:2009-01-28 13:07:32

标签: python distributed

我在项目中使用Pyro,似乎无法理解如何通过网络传输完整的对象。对象分布式(我的分布式对象工作得很好),但应该作为已经可用的分布式对象的参数。

我的对象是从包含一些方法和一些变量的自定义类派生而来的 - 整数和列表。该类可用于服务器和客户端。当我使用我的对象作为分布式对象的方法的参数时,整数变量被正确地“接收”,但是列表是空的,即使我可以看到它在“发送”之前包含值。

为什么会这样?

班级的简短版本:

class Collection(Pyro.core.ObjBase):
    num = 0
    operations = [("Operation:", "Value:", "Description", "Timestamp")]

def __init__(self):
    Pyro.core.ObjBase.__init__(self)

def add(self, val, desc):
    entry = ("Add", val, desc, strftime("%Y-%m-%d %H:%M:%S"))
    self.operations.append(entry)
    self.num = self.num + 1

def printop(self):
    print "This collection will execute the following operations:"
    for item in self.operations:
        print item

分布式对象中的receving方法:

def apply(self, collection):
    print "Todo: Apply collection"
    #op = collection.getop()
    print "Number of collected operations:", collection.a
    collection.printop()

2 个答案:

答案 0 :(得分:4)

操作是类属性,而不是对象属性。这就是它没有转移的原因。尝试通过__init__self.operations = <whatever>中进行设置。

答案 1 :(得分:1)

您的接收方法 apply 与内置Python函数同名。

相关问题