dbm - Python dumbdbm, when will data be written back to disk? -
i'm using python2.7's dumbdbm
, question applies python3's dbm.dumb
.
the documentation says:
dumbdbm.sync()
synchronize on-disk directory , data files. method called sync() method of shelve objects.
i've got 3 questions:
one — perhaps best if not — way answer questions aren't addressed in documentation read source code (when it's available, here).
the dumbdbm.py
file should in /python/lib
directory , can viewed online in browser through mercurial source code revision control system at:
https://hg.python.org/cpython/file/2.7/lib/dumbdbm.py
the first thing notice longish comment @ beginning of private _database
class — dumbdbm
database — because seems deal seems overall theme of questions:
class _database(userdict.dictmixin): # on-disk directory , data files can remain in mutually # inconsistent states arbitrarily long time (see comments # @ end of __setitem__). repaired when _commit() # gets called. 1 place _commit() gets called __del__(), # , if occurs @ program shutdown time, module globals may # have gotten rebound none. since it's crucial # _commit() finish successfully, can't ignore shutdown races # here, , _commit() must not reference globals.
in-depth information specific methods can found reading source code them. given that, here's think answers questions version 2.7 of python:
if don't call
sync
, disk file updated?from preceding comment, sounds long program shuts down gracefully.
beyond depends on methods have been called. may, partially. instance, looks
__setitem__()
does, depending on whether item entirely new key or existing one. latter cases there's comment @ end of part deals them says (realizing_commit()
namesync()
):note
_index
may out of synch directory file now:_setval()
,_addval()
don't update directory file. means on-disk directory , data files in mutually inconsistent state, , they'll remain way until_commit()
called. note disaster (for database) if program crashes (so_commit()
never gets called).and function write data disk, not inverse?
sync()
/_commit()
not appear load data memory disk.what if call
close
?close()
calls_commit()
, sets internal data structuresnone
, preventing further database operations.
in conclusion, humorous take on meta-subject here, suggest read learn read source, luke.
Comments
Post a Comment