New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dumbdbm __del__ bug #38156
Comments
I used shelve.py and it falls back on dumbdbm when no I found this error, which is recurrent and deterministic: Exception exceptions.AttributeError: "'NoneType' object The problem seems to reside in the __del__ of 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 The reason I suspect is when the time that 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. |
Logged In: YES see the thread at http://groups.google.com/groups? |
Logged In: YES Can you provide a test case which triggers this problem? I |
Logged In: YES A test case that triggers this problem: #foobar.py
def open(filename, flag='c'):
import dumbdbm
return dumbdbm.open(filename,flag)
c=open('test.dbm')
#main.py
import foobar $ python main.py
>>>
Exception exceptions.TypeError: "'NoneType' object is not
callable" in <bound method _Database.__del__ of
<dumbdbm._Database instance at 0x401e482c>> ignored |
Logged In: YES Run the main.py in Python 2.3+ putting the two files in the For Python 2.2+, put the two files in the same package and ======= |
Logged In: YES Tested on linux and windows xp with Python2.2.2 and |
Logged In: YES Neal, this is actually a common problem in __del__ In general, a __del__ method should never reference Reimporting a module instead may not be effective (if it's in |
Logged In: YES OK, so according to Tim all the accessing of _os should be |
Logged In: YES Tim, is this what you just fixed? |
Logged In: YES Raymond, yes, and thanks for the reminder. This is fixed in |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: