boltdb
boltdb copied to clipboard
KeyError: 0
When a db is opened and closed multiple times, like you run the file multiple times not altogether, one after; I am getting a key error.
Traceback (most recent call last):
File "/mnt/d/python-based-client/test/test.py", line 11, in
This is the error and I am putting my code below. What I did is I just run this python file multiple times using a shell script.
test.py
from boltdb import BoltDB
from datetime import datetime
db = BoltDB('chat_history.db')
with db.update() as tx:
# bkt = tx.create_bucket(b"new_chats") run this only first time
bkt = tx.bucket(b"new_chats")
bkt.put(str(datetime.now()).encode('utf-8'), "test".encode('utf-8'))
tx.commit()
with db.update() as tx:
bkt = tx.bucket(b"new_chats")
for k, v in bkt:
print(k.decode('utf-8'))
print(v.decode('utf-8'))
tx.commit()
Shell script is:
a=1
while [ $a -lt 100 ];
do
python3.12 test.py
a=$((a+1))
echo $a
sleep 1
done