--- py3k/Lib/shelve.py.orig 2009-03-13 20:42:45.000000000 +0800 +++ py3k/Lib/shelve.py 2009-03-13 20:44:49.000000000 +0800 @@ -210,6 +210,32 @@ Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback) +class FastDbfilenameShelf(DbfilenameShelf): + """Shelf implementation without cache sync when writeback=True. + + This implementation will never write back cached entries. Thus there's no + delay during shelf close, but has potential data lose risk. + + To avoid data lose, never do this even with writeback=True: + + d['xx'] = range(4) # this works as expected, but... + d['xx'].append(5) # *this doesn't!* -- d['xx'] is STILL range(4)!!! + + Instead always use: + + temp = d['xx'] # extracts the copy + temp.append(5) # mutates the copy + d['xx'] = temp # stores the copy right back, to persist it + """ + + def __init__(self, filename, flag='c', protocol=None, writeback=True): + DbfilenameShelf.__init__(self, filename, flag, protocol, writeback) + + def sync(self): + if hasattr(self.dict, 'sync'): + self.dict.sync() + + def open(filename, flag='c', protocol=None, writeback=False): """Open a persistent dictionary for reading and writing.