tasksystem.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:deepjets 作者: deepjets 项目源码 文件源码
def save_global(self, obj, name=None, pack=pickle.struct.pack):
        assert obj
        assert id(obj) not in self.memo
        if name is None:
            name = obj.__name__

        module = getattr(obj, "__module__", None)
        if module is None or module == "__main__":
            module = pickle.whichmodule(obj, name)
        if module is None or module == "__main__":
            raise pickle.PicklingError(
                    "Can't pickle %r: module not found: %s" % (obj, module))

        try:
            __import__(module)
            mod = sys.modules[module]
            klass = getattr(mod, name)
        except (ImportError, KeyError, AttributeError):
            raise pickle.PicklingError(
                    "Can't pickle %r: it's not found as %s.%s" % (obj, module, name))
        else:
            if klass is not obj:
                raise pickle.PicklingError(
                        "Can't pickle %r: it's not the same object as %s.%s" % (obj, module, name))

        assert "\n" not in module
        assert "\n" not in name
        self.write(pickle.GLOBAL + module + '\n' + name + '\n')
        self.memoize(obj)

    # Some types in the types modules are not correctly referenced,
    # such as types.FunctionType. This is fixed here.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号