R
R
Radiss2022-02-12 23:16:22
SQLite
Radiss, 2022-02-12 23:16:22

Why is telegram sqlite3 database locked?

After processing incoming messages, other people's comments appeared. in the telegram channel and immediately the database is locked

main.py

from pyrogram import Client

api_id =
api_hash = ""

@app.on_message()
async def my_handler(client, message):
await message.forward("me")

app.run()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Dedinets, 2022-02-12
@donko1

because the database is open in another file or something like that. sqlite3 works on the principle that when someone reads, other files cannot. Simply put, try to open sqlite3 only at the right moments. That is, do not write

conn = sqlite.connect(*arg)
#some code here
conn.close()

a
with sqlite.connect(*arg) as conn: 
 #some code here

Also, you should not open the database in other files all the time. They must be closed at the same moment when you received or wrote down the necessary information.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question