Reputation: 467
I am using Python with SQLite currently and wondering if it is safe to have multiple threads reading and writing to the database simultaneously. Does SQLite handle data coming in as a queue or have sort of mechanism that will stop the data from getting corrupt?
Upvotes: 2
Views: 1905
Reputation: 622
This is my issue too. SQLite using some kind of locking mechanism which prevent you doing concurrency operation on a DB. But here is a trick which i use when my db are small. You can select all your tables data into memory and operate on it and then update the original table.
As i said this is just a trick and it does not always solve the problem.
I advise to create your trick.
Upvotes: 3
Reputation: 211570
SQLite has a number of robust locking mechanisms to ensure the data doesn't get corrupted, but the problem with that is if you have a number of threads reading and writing to it simultaneously you'll suffer pretty badly in terms of performance as they all trip over the others. It's not intended to be used this way, even if it does work.
You probably want to look at using a shared database server of some sort if this is your intended usage pattern. They have much better support for concurrent operations.
Upvotes: 2