I want to understand the correct way to read/write/close with multiple databases. For example,
# open an env
env = open_env(data_folder, map_size, writemap=True)
# open db1
db1 = open_db(env, "db1".encode())
# open db2
db2 = open_db(env, "db2".encode())
# read from db2
with env.begin(db2, write=True) as txn:
for i in range(1000):
kv = txn.get(str(i).encode())
My assumption is:
Once the env and the 2 databases are opened, the 2 databases can be read and written to. On exit from the 'with' context-manager, the env and the 2 databases are closed automatically so data can be flushed to disk.
But:
Shouldn't the env (specifically) and the databases remain open until explicitly closed otherwise they are continuously being opened and closed for each set of transactions on the databases?
I want to understand the correct way to read/write/close with multiple databases. For example,
My assumption is: Once the env and the 2 databases are opened, the 2 databases can be read and written to. On exit from the 'with' context-manager, the env and the 2 databases are closed automatically so data can be flushed to disk.
But: Shouldn't the env (specifically) and the databases remain open until explicitly closed otherwise they are continuously being opened and closed for each set of transactions on the databases?