0

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

/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))

有人可以告诉我造成此错误的可能性或我该如何解决?

4

1 回答 1

2

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)

Or by object inspection.

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

There's also dill.detect.badtypes and so on.

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

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

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.

于 2014-08-11T13:13:04.177 回答