dill 在dill.detect 中有pickle 调试工具。我看不到您要调试的对象,因为您上面的代码不是由于 pickle... 但无论如何我都可以在下面展示一个示例。
>>> class Test(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
...
>>> x = (i for i in range(10))
>>> y = iter(range(10))
>>>
>>> t = Test(x,y)
>>>
>>> import dill
>>> dill.detect.errors(t)
PicklingError("Can't pickle <type 'listiterator'>: it's not found as __builtin__.listiterator",)
>>> dill.detect.badobjects(t)
<__main__.Test object at 0x1086970d0>
>>> dill.detect.badobjects(t, 1)
{'__hash__': <method-wrapper '__hash__' of Test object at 0x1086970d0>, '__setattr__': <method-wrapper '__setattr__' of Test object at 0x1086970d0>, '__reduce_ex__': <built-in method __reduce_ex__ of Test object at 0x1086970d0>, 'y': <listiterator object at 0x108890d50>, '__reduce__': <built-in method __reduce__ of Test object at 0x1086970d0>, '__str__': <method-wrapper '__str__' of Test object at 0x1086970d0>, '__format__': <built-in method __format__ of Test object at 0x1086970d0>, '__getattribute__': <method-wrapper '__getattribute__' of Test object at 0x1086970d0>, '__delattr__': <method-wrapper '__delattr__' of Test object at 0x1086970d0>, '__repr__': <method-wrapper '__repr__' of Test object at 0x1086970d0>, '__dict__': {'y': <listiterator object at 0x108890d50>, 'x': <generator object <genexpr> at 0x108671f50>}, 'x': <generator object <genexpr> at 0x108671f50>, '__sizeof__': <built-in method __sizeof__ of Test object at 0x1086970d0>, '__init__': <bound method Test.__init__ of <__main__.Test object at 0x1086970d0>>}
>>> dill.detect.trace(True)
>>> dill.dumps(t)
T2: <class '__main__.Test'>
F2: <function _create_type at 0x10945c410>
T1: <type 'type'>
F2: <function _load_type at 0x10945c398>
T1: <type 'object'>
D2: <dict object at 0x10948b7f8>
F1: <function __init__ at 0x108894938>
F2: <function _create_function at 0x10945c488>
Co: <code object __init__ at 0x108873830, file "<stdin>", line 2>
F2: <function _unmarshal at 0x10945c320>
D1: <dict object at 0x1085b9168>
D2: <dict object at 0x10947e910>
D2: <dict object at 0x108898910>
T4: <type 'listiterator'>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
#...snip...
pickle.PicklingError: Can't pickle <type 'listiterator'>: it's not found as __builtin__.listiterator
>>>
我想不出有一个 AssertionError 和 pickle.dump 从我的头顶冒出来的情况......但上述调试工具在这种情况下应该以完全相同的方式工作。
如果您发布一个简单的可重现对象(最好是标准库),它会在酸洗时产生 AttributeError,我将更新我的示例。