pickle error assert id(obj) not in self.memo

2019-09-04 05:57发布

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?

1条回答
冷血范
2楼-- · 2019-09-04 06:46

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.

查看更多
登录 后发表回答