Writing multiple threads in SQLite in Python

I have a sqlite3 database and I want to write to it from multiple threads. I have a few ideas, but I'm not sure what I should implement.

  • create a multiple connection, detect and disconnect if the database is locked.
  • use one connection and try using serialized connections (which don't seem to be implemented in python)
  • has a one-connection background process that collects requests from all threads and then executes them on its behavior
  • forget about SQlite and use something like Postgresql

What are the achievements of these different approaches and which are likely to be fruitful? Are there any other options?

+4
source share
2 answers

Try using https://pypi.python.org/pypi/sqlitedict Lightweight wrapper around the python sqlite3 database with voice recorder support and multi-threaded access. But keep in mind that "concurrent queries are still serialized internally, so this" multithreaded support "does not give you any performance advantages. This is a limitation for sqlite restrictions in Python."

PostgreSQL, MySQL, etc. give you better performance for multiple connections at a time

0
source

1 . . -, . .

3 . , , , " " . . .

. db, MS SQL/MySQL.

0

All Articles