[Python-Dev] improving dumbdbm's survival chances...

Skip Montanaro skip@pobox.com
Sun, 13 Jul 2003 13:32:15 -0500

(CC'ing python-dev because I think there's a simple improvement/fix for
dumbdbm here.)

I realize we (the Spambayes folks) want to discourage people from using
dumbdbm, but for those who are either stuck with it or don't realize they
are using it, I wonder if we can do a little something to help them out.

As I understand it, if a machine crashes or is shut down without exiting
Outlook, there's a good chance that the dumbdbm's _commit method won't have
been called and the directory and data files will be out-of-sync.  It seems
that dumbdbm doesn't support a sync() method which shelve likes to call.
Shelve's sync method gets called from time-to-time by the Spambayes storage
code.  dumbdbm.sync has this statement:

    if hasattr(self.dict, 'sync'):

so maybe it's as simple (short-term) as modifying dbmstorage.open_dumbdbm()

    def open_dumbdbm(*args):
        """Open a dumbdbm database."""
        import dumbdbm
        db = dumbdbm.open(*args)
        if not hasattr(db, "sync"):
            db.sync = db._commit
        return db

The above should help.  Meanwhile, it appears that would be a good method to
add to dumbdbm databases both for 2.3 and the 2.2 maintenance branch.