在搁置模块中发现了一个奇怪的异常(好吧,搁置助手copy_reg模块)。看一看,它正在尝试调用对应该是Pickler类的__getstate__方法的引用。但是,由于某些原因,这似乎没有返回任何结果。我只是想知道是否有其他人经历过这种情况,以及是否可以做些什么来让shelve正常工作?
下面是我看到的异常的返回堆栈:
File "/usr/local/lib/python2.7/dist-packages/libgsync/drive/__init__.py", line 497, in stat
self._pcache[search] = ent
File "/usr/lib/python2.7/shelve.py", line 132, in __setitem__
p.dump(value)
File "/usr/lib/python2.7/copy_reg.py", line 84, in _reduce_ex
dict = getstate()
DEBUG: libgsync/drive/__init__.py:387:walk(): Exception: 'NoneType' object is not callable我冒然查看了代码,这里是_reduce_ex()函数中出现故障的地方:
try:
getstate = self.__getstate__
except AttributeError:
if getattr(self, "__slots__", None):
raise TypeError("a class that defines __slots__ without "
"defining __getstate__ cannot be pickled")
try:
dict = self.__dict__
except AttributeError:
dict = None
else:
dict = getstate()最初,它将self.__getstate__赋值给getstat,因此此时这应该是可调用的。它似乎没有引发异常,因为它是在else块的上下文中执行的。奇怪的是。
以下是发生异常的代码行的调试输出:
DEBUG: libgsync/drive/__init__.py:496:stat(): Updating path cache: /unittest下面是导致异常的代码:
# Update path cache.
if self._pcache.get(search) is None:
debug("Updating path cache: %s" % search)
self._pcache[search] = ent发布于 2013-06-02 03:54:47
分配给工具架字典的值不是可复制的对象。我通过将字典的类包装推迟到缓存之后解决了这个问题。
https://stackoverflow.com/questions/16876364
复制相似问题