dumbdbm module broken in Python2.3?
Jane Austine
janeaustine50 at hotmail.com
Tue Mar 11 16:37:39 EST 2003
I used shelve.py and it falls back on dumbdbm when no
possible alternatives are found on the system.
I found this error, which is recurrent and deterministic:
Exception exceptions.AttributeError: "'NoneType' object has no
attribute 'error'" in <bound method _Database.__del__ of
<dumbdbm._Database instance at 0x820c71c>> ignored
The problem seems to reside in the __del__ of dumbdbm._Database:
class _Database:
...
def __del__(self):
if self._index is not None:
self._commit()
...
def _commit(self):
try: _os.unlink(self._bakfile)
except _os.error: pass
try: _os.rename(self._dirfile, self._bakfile)
except _os.error: pass
f = _open(self._dirfile, 'w', self._mode)
for key, (pos, siz) in self._index.items():
f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`))
f.close()
My investigation showed that the error was from _commit. When
it was called, _os or _open was both None. And the exception
catch didn't work quite safely cause its in the "except" clause.
The reason I suspect is when the time that _Database.__del__ was
called the os module(which is imported as _os) is already removed out.
I changed the code as:
def _commit(self):
global _os
if _os is None:
import os as _os
import __builtin__
_open = __builtin__.open
try: _os.unlink(self._bakfile)
except _os.error: pass
try: _os.rename(self._dirfile, self._bakfile)
except _os.error: pass
......
Now it works without any problems, AFAIK.
Am I right on the track?
Jane
More information about the Python-list
mailing list