本文介绍了泡菜错误声明id(obj)不在self.memo中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用莳萝(泡菜的高级版本).我想序列化对象,但是出现此错误:

I am using dill (advanced version of pickle) right now. I want to serialize my object, but I get this error:

/usr/lib/python2.7/pickle.pyc in memoize(self, obj)
    242         if self.fast:
    243             return
--> 244         assert id(obj) not in self.memo
    245         memo_len = len(self.memo)
    246         self.write(self.put(memo_len))

有人可以告诉我发生此错误的可能性,或者我该如何解决呢?

Can someone tell me the possibility that made this error or how can I solved this?

推荐答案

如果不发布简化版本的代码,将很难提供帮助.但是,dill具有一些内置的检测方法.看dill.detect.

Without you posting a reduced version of your code, it's hard to help. However, dill has some builtin detection methods. Look at dill.detect.

>>> # trace dill's pickling of objects, by printing out step by step trace 
>>> dill.detect.trace(True)

或者通过物体检查.

>>> dill.detect.badobjects(yourfailingobject, depth=1)

还有dill.detect.badtypes等等.

或者您可以使用dill.detect.parentdill.detect.childrendill.detect.reference等来跟踪对象之间的关系.

Or you can trace down how objects relate to each other, with dill.detect.parent, dill.detect.children, dill.detect.reference, and so on.

这里是一个使用dill(为可视化加上objgraph)来跟踪循环引用的示例. https://github.com/uqfoundation/dill/issues/58

Here's an example of using dill (plus objgraph for visualization) to track down circular references. https://github.com/uqfoundation/dill/issues/58

dill也不知道如何在dill._objects中进行序列化,这也是一个很大的清单-至少是python标准库的前15个部分,还有其他一些.

There's also a big list of all that dill does not know how to serialize in dill._objects -- at least the first 15 sections of the python standard library, plus some others.

这篇关于泡菜错误声明id(obj)不在self.memo中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:32