[Python-bugs-list] [ python-Bugs-702775 ] dumbdbm __del__ bug
SourceForge.net
noreply@sourceforge.net
Wed, 12 Mar 2003 22:27:19 -0800
Bugs item #702775, was opened at 2003-03-13 15:27
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=702775&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Jane Austine (janeaustine50)
Assigned to: Nobody/Anonymous (nobody)
Summary: dumbdbm __del__ bug
Initial Comment:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=702775&group_id=5470