* ``'s'``: Synchronized mode.
Changes to the database will be written immediately to the file.
* ``'u'``: Do not lock database.
- * ``'m'``: Do not use :manpage:`mmap(2)`.
- This may harm performance, but improve crash tolerance.
- .. versionadded:: next
Not all flags are valid for all versions of GDBM.
See the :data:`open_flags` member for a list of supported flag characters.
which allow to recover unused free space previously occupied by deleted entries.
(Contributed by Andrea Oliveri in :gh:`134004`.)
-* Add the ``'m'`` flag for :func:`dbm.gnu.open` which allows to disable
- the use of :manpage:`mmap(2)`.
- This may harm performance, but improve crash tolerance.
- (Contributed by Serhiy Storchaka in :gh:`66234`.)
difflib
# Test the flag parameter open() by trying all supported flag modes.
all = set(gdbm.open_flags)
# Test standard flags (presumably "crwn").
- modes = all - set('fsum')
+ modes = all - set('fsu')
for mode in sorted(modes): # put "c" mode first
self.g = gdbm.open(filename, mode)
self.g.close()
- # Test additional flags (presumably "fsum").
+ # Test additional flags (presumably "fsu").
flags = all - set('crwn')
for mode in modes:
for flag in flags:
create_empty_file(os.path.join(d, 'test'))
self.assertRaises(gdbm.error, gdbm.open, filename, 'r')
- @unittest.skipUnless('m' in gdbm.open_flags, "requires 'm' in open_flags")
- def test_nommap_no_crash(self):
- self.g = g = gdbm.open(filename, 'nm')
- os.truncate(filename, 0)
-
- g.get(b'a', b'c')
- g.keys()
- g.firstkey()
- g.nextkey(b'a')
- with self.assertRaises(KeyError):
- g[b'a']
- with self.assertRaises(gdbm.error):
- len(g)
-
- with self.assertRaises(gdbm.error):
- g[b'a'] = b'c'
- with self.assertRaises(gdbm.error):
- del g[b'a']
- with self.assertRaises(gdbm.error):
- g.setdefault(b'a', b'c')
- with self.assertRaises(gdbm.error):
- g.reorganize()
-
if __name__ == '__main__':
unittest.main()