蟒蛇ZODB - 数据对象不是两个运行文件之间持续存在的

问题描述

我有两个蟒文件。一种是通过网站后台被服务的服务器。它实质上是一个控制器,该控制器增加/编辑/删除条目到ZODB FileStorage实例

我有一个巨大的文件的数量进行迁移,所以我想通过服务器手动去代替,我会使用一个脚本文件。因此,有正在使用另一个脚本加速更新分贝,而不是使用该网站的过程。

这是被用于管理ZODB的代码。它是在脚本和服务器是相同的:

    class ZContainer(persistent.Persistent):
    """Empty container class for storing persistent data in ZODB."""
        pass


    class ZData:
    """Dictionary-like class for persisting data in ZODB database"""

        def __init__(self,pathname):
            self.storage = ZODB.FileStorage.FileStorage(pathname)
            self.db = ZODB.DB(self.storage)
            connection = self.db.open()
            root = connection.root()

            try:

                container = root.container
            except:

                # initial setup
                root.container = BTrees.OOBTree.BTree()
                transaction.commit()
                container = root.container
                connection.close()

        def __setitem__(self,key,value):
            connection = self.db.open()
            root = connection.root()
            container = root.container
            o = ZContainer()
            o.data = value
            o._p_changed = True
            container[key] = o
            transaction.commit()
            connection.close()

        def __getitem__(self,key):
           connection = self.db.open()
            root = connection.root()
            container = root.container
            d = copy.deepcopy(container[key].data)
            connection.close()
            return d

这两个方案都指向在存储相同的文件。然而,例如,如果我尝试从服务器获取一个项目,我用的脚本,以创建,被抛出了以下错误:

AttributeError: 'ZContainer' object has no attribute 'data'

,表示密钥被更新,但数据值不可读的某些原因。记住的代码是在这两个地方完全一样。如果我使用的脚本文件就可以访问相同的项目,它成功地执行和数据持久化。只有当我尝试通过其他文件访问的项目,这个错误出现。

下面是两个运行文件主代码:

    def create_archive(self,u,properties,data):
        global zodb # instance of ZDATA
        if properties["filename"] == 'acl':
            return False
        m = hashlib.sha256()
        dat = base64.b64decode(data['data'])
        m.update(dat)
        hash = m.hexdigest()
        properties['hash'] = hash
        zodb[hash] = properties
        return True

这里发生了什么?不ZODB不允许从两个不同的文件修改存储?有没有办法得到这个工作?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)