[New-bugs-announce] [issue6932] Open shelves fail when Python exits

Robert Lehmann report at bugs.python.org
Thu Sep 17 17:55:57 CEST 2009


New submission from Robert Lehmann <lehmannro at gmail.com>:

I'm reopening issue5483 by Zhigang Wang (zhigang) as a separate bug.

Shelves that are still open when Python terminates will try to sync. If
writeback=True, this pickles cached items.

In this example, serialization of Test() re-imports __main__, which is
already gc'd, and raises:
Exception cPickle.PicklingError: Can't pickle <class '__main__.Test'>:
it's not the same object as __main__.Test" in <bound method
Shelf.__del__ of {'a': <__main__.Test object at 0x...>}>

The error is ignored (due to Python already tearing down) but all cached
modifications are lost.
The promise "[t]he __del__() method of the Shelf class calls the close()
method, so the programmer generally need not do this explicitly" is not
true with writeback enabled.

I'm unsure if this error can be fixed (probably with atexit/weakref, but
that's more trouble than gain). I attached a patch to the docs simply
warning the user of this issue (+ documenting Shelf.close, + removing
above quote).

----------
assignee: georg.brandl
components: Documentation, Extension Modules, Library (Lib)
files: example.py
messages: 92773
nosy: georg.brandl, lehmannro
severity: normal
status: open
title: Open shelves fail when Python exits
type: behavior
versions: Python 2.7, Python 3.1
Added file: http://bugs.python.org/file14912/example.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6932>
_______________________________________


More information about the New-bugs-announce mailing list