[Python-Dev] RE: [spambayes-dev] improving dumbdbm's survival chances...

Skip Montanaro skip@pobox.com
Sun, 13 Jul 2003 20:26:41 -0500


    >> 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:

    Tim> No, you're quoting shelve.py here:

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

Yup.  The Spambayes storage code calls Shelve's sync method.  It in turn (in
the code I quoted) will call the underlying db module's sync method if it
has it.  It seems to me that dumdbm's _commit() method is the same as the
sync() method which Shelve is looking for.

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

    Tim> That would help spambayes a lot, because DBDictClassifier.store()
    Tim> does call self.db.sync() on its Shelf at the important times. 

Yeah, that's what I was getting at.

    Tim> People using dumbdbm with spambayes would still be a lot better off
    Tim> using a plain in-memory dict, though (on all counts: it would
    Tim> consume less memory, consume less disk space for the dict pickle,
    Tim> and run faster).

    Tim> Fine by me, although I doubt a 2.2.4 will get released.  Adding

    Tim>     sync = _commit

    Tim> to the 2.3 code (+ docs + test) should be sufficient.

I'm willing to do that.  Martin seemed to disagree that it should go in
until after 2.3 is released.  I'll submit a patch and let others decide.

Skip