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:

  1. if don't call sync, disk file updated?
  2. and function write data disk, not inverse?
  3. what if call close?

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:

  1. 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() name sync()):

    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).

  2. and function write data disk, not inverse?

    sync() / _commit() not appear load data memory disk.

  3. what if call close?

    close() calls _commit() , sets internal data structures none, preventing further database operations.

in conclusion, humorous take on meta-subject here, suggest read learn read source, luke.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -