U
U
UserTypical32021-03-26 23:06:07
Python
UserTypical3, 2021-03-26 23:06:07

Can sqlite3 be used in an asynchronous bot?

Hello.
I write discord bots. I use sqlite3 in my bots.
I was told that with a large number of queries it will give an error Database is locked
And they gave an example:

There is one girl - a SQLite3 file
And a lot of men - requests

And these men are trying all together at one moment to insert their f*cking *organ girl.

Is this true or false?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2021-03-26
@UserTypical3

True, it is single-threaded, and if you try to access from several threads, it will throw a blocking error. While one flow processes the data - db is locked. In principle, it is comparable to trying to open the same file twice.
It's better to use a full database like postgres for example. It has more fields and supports access from multiple threads. sqlite3 can also be played for tests, in fact it is a simple key-value storage with the most primitive data: int, real, blob, text, like a database in a dictionary in a .json file.

H
HemulGM, 2021-03-27
@HemulGM

It is enough to organize a queue of requests. Those. while one request is in progress, do not allow the second one to be executed.
If there is no heavy load on the database, then sqlite will handle it.
Otherwise, use any client-server database.

A
Anton Konovalov, 2021-03-27
@akonovalov

Recently worked with SQLite from Python 3.8 with aiohttp.
Used the aiosqlite library .
There were no blocking errors with it, when trying to write in parallel - everything was written, but with expectation. Apparently, she knows how to lock the file when writing by one person and the rest are "waiting".
The main inconvenience for me was the lack of a normal asynchronous ORM for working with SQLIte,
although for its class of tasks (prototypes, lightly loaded and little used services) - IMHO it is quite a suitable solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question