ZODB python 带文件存储的数据库:为什么临时文件留在磁盘上?

ZODB python database with Filestorage: why do temporary files stay on the disk?

我正在 Python 3.6 中试验 ZODB 数据库模块。在我的实验中,我创建了一个 TreeSet() 并用数据填充它。然后我提交事务(将更改保存到磁盘)并关闭数据库。

from ZODB.FileStorage import FileStorage
from ZODB import DB
from persistent import Persistent
from BTrees.OOBTree import TreeSet
import transaction

if __name__ == '__main__':
    # 1. Create ZODB database
    # ------------------------
    storage = FileStorage("C:/database_test/mydb.db")
    db = DB(storage)
    conn = db.open()
    root = conn.root()
    root.files = TreeSet()


    # 2. Fill the TreeSet
    # --------------------
    ...

    # 3. Save and close
    # ------------------
    transaction.commit()
    conn.close()
    db.close() # <- is this even necessary?

我查看硬盘上剩余的文件。如您所见,那里还保留着三个临时文件 - 即使在我关闭数据库之后也是如此。

我是否关闭了某些东西(数据库连接存储transaction, ...) 不正确?


注:
我不知道这是否重要,但我的系统如下:

不,它们不是真正的临时文件。它们是永久性文件,有时包含临时数据。

In addition to the data file, some ancillary files are created. These can be lost without affecting data integrity, however losing the index file may cause extremely slow startup. (http://www.zodb.org/en/latest/reference/storages.html#included-storages)

.index文件不是临时文件,而是持久化的索引文件。如果不存在,它将始终完全重新生成(对于较大的数据库,这将花费一些时间)。

.temp 文件用于在完全提交之前生成的临时数据。

.lock文件是为了保证没有两个进程打开那个文件。它包含打开它的最后一个进程的 PID。如果它终止了一个新进程,然后将其 PID 写入其中。

实际上还有比这更多的文件,它们记录在 class docstring.