【发布时间】:2020-06-17 12:50:51
【问题描述】:
python 版本从 3.5 更改为 3.7 后,shelve 在调用 sync 方法时不再写入磁盘。但是,当我使用 python 3.5 时,它确实如此。
我还注意到在 python 3.7 上,“db”扩展名被附加到搁置数据库文件中。
有人知道这是什么原因吗?有什么解决方法吗?
【问题讨论】:
python 版本从 3.5 更改为 3.7 后,shelve 在调用 sync 方法时不再写入磁盘。但是,当我使用 python 3.5 时,它确实如此。
我还注意到在 python 3.7 上,“db”扩展名被附加到搁置数据库文件中。
有人知道这是什么原因吗?有什么解决方法吗?
【问题讨论】:
原来我错过了 python3.7-gdbm 包(它是一个 Ubuntu Xenial 服务器)。
可以用apt-get安装:
sudo apt-get install python3.7-gdbm
安装 gdbm 包后,python 将开始将搁置存储为 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
【讨论】: