I'm experimenting with the ZODB database module in Python 3.6. In my experiment, I create a TreeSet()
and fill it with data. Then I commit the transaction (which saves the changes to disk) and close the database.
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?
I look at the files remaining on my harddrive. As you can see, there are three temporary files remaining there - even after I've closed the database.
Did I close something (database, connection, storage, transaction, ...) not properly?
Note:
I don't know if this is important, but my system is as follows:
The .index
file is not a temporary file, but it is the index file that is persisted. If absent, it will always be fully regenerated (which will take a bit of time for a larger database).
The .temp
file is for transient data that is generated before being fully committed.
The .lock
file is to ensure that no two process open that file. It contains the PID of the last process that opened it. If it has terminated a new process will then write its PID into it.
There are actually more files than this, and they are documented inside the class docstring.