gpt4 book ai didi

python bsddb 删除条目时不会刷新

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:17 24 4
gpt4 key购买 nike

我有一个 python BSDDB 数据库。显然,它存储在硬盘上。当我删除一些条目时,驱动器上的文件不会变小(因此 - 它增长得相当快......)

utDelList   = []
urlsDelList = []
for ut in iter(self.urls2task):

tmp = string.split(ut, ":")
uid = tmp[1]
url = cPickle.loads(self.urls[int(uid)])
urlsDelList.append(uid)
utDelList.append(ut)
del self.urlsDepth[uid]
del self.urlsStatus[uid]
del url

for ut in utDelList:
del self.urls2task[ut]

for uid in urlsDelList:
del self.urls[int(uid)]

(...)
#synchronize all files
self.sync()

我最后的希望是以一种野蛮的方式强制刷新 - 通过再次关闭和打开文件

#close all files & start them again, eg
self.tasks.close()
self.urls2task.close()
self.tasks = bsddb.rnopen(filepath)
self.urls2task = bsddb.hashopen

这里的关键元素是 self.tasks 条目;它是所有文件中增长最快、最大的。酸洗保存是否会改变去除它的方式?而且,再一次 - 为什么文件在删除条目后仍然保留条目?如果有任何建议,我将不胜感激(这里是第一篇文章:))

最佳答案

您是否尝试使用 db.compact()方法?

根据文档:

compact(start=None, stop=None, flags=0, compact_fillpercent=0, compact_pages=0, compact_timeout=0)

Compacts Btree and Recno access method databases, and optionally returns unused Btree, Hash or Recno database pages to the underlying filesystem.

The method returns the number of pages returned to the filesystem.

听起来应该减少磁盘上数据库的大小

关于python bsddb 删除条目时不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com