Parallel Records Using SQLite and Peewee

I plan to use SQLite and Peewee (ORM) for a lightweight internal web service (<20 requests per second). A web service can handle multiple simultaneous requests across multiple threads. During each request, the database will be read and written. This means that I will need to be able to read and write at the same time. It does not matter for this application if the data changes between reading and writing.

The SQLite FAQ says that concurrent reads are allowed, but simultaneous writing from multiple threads requires acquiring a file lock. My question is: Will Peewee take care of this blocking for me, or is there something I need to do in my code to make this possible?

The Peewee database object is shared between threads. I assume this means that the database connection is also shared.

I cannot find a specific Peewee answer, so I ask here.

+3
source share
2 answers

Sqlite is the one who does the lock, although I see how you can confuse - the wording of the frequently asked questions is somewhat ambiguous:

When a process wants to write, it must lock the entire database file while it is being updated. But it usually takes only a few milliseconds. Other processes just wait for the writer to finish and then continue his business. Other embedded SQL database kernels typically allow only one process to connect directly to the database.

, , , , , , .

pysqlite, 5 , 5 , OperationalError.

, SqliteDatabase threadlocals=True. .

+3

async. Javascript ( ). , :

SQLITE:

.

, async python, , . SQLAlchemy + , , , .

+1

All Articles