关闭前搁置不同步到磁盘

shelve does not sync to disk before close

将python的版本从3.5改为3.7后,调用sync方法时shelve不再写入磁盘。但是,当我使用 python 3.5 时它确实如此。

我还注意到 python 3.7 上的 'db' 扩展名附加到搁置数据库文件。

有人知道这是什么原因吗?有什么解决方法吗?

原来我缺少 python3.7-gdbm 包(这是一个 Ubuntu Xenial Server)。

可以用apt-get安装:

sudo apt-get install python3.7-gdbm

安装 gdbm 包后 python 将开始将 shelve 存储为 GNU dbm 而不是 Berkeley DB:

$ file *
shelve_obj_berkley:            Berkeley DB (Hash, version 9, native byte-order)
shelve_obj_gdbm:               GNU dbm 1.x or ndbm database, little endian, old