userdict和userlist似乎在pickle模块中工作不稳定。如何修复此错误:
测试_泡菜.pyimport pickle
class UserList(list):
pass
class UserDict(dict):
pass
u = UserList([])
for i in range(10):
d = UserDict()
d.u = u
u.append(d)
pickle.dump(u, open("ttt.pcl", 'wb'))
$python测试_泡菜.py在
^{pr2}$
现在,如果我增加UserList中元素的数量,它会变得“更好”:import pickle
class UserList(list):
pass
class UserDict(dict):
pass
u = UserList([])
for i in range(100):
d = UserDict()
d.u = u
u.append(d)
pickle.dump(u, open("ttt.pcl", 'wb'))
$python测试_泡菜.py在...
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 71, in _reduce_ex
state = base(self)
RuntimeError: maximum recursion depth exceeded while calling a Python object