To fully utilize concurrency, SQLite3 allows threads to access the same connection in three ways:
Does anyone know how I can make the connection serialized in Python.
Python has "check_same_thread" which allows switching between multi-threading and single-threading; however, I can not find out how I should make it serialized.
SQLite Python: Querying Data First, establish a connection to the SQLite database by creating a Connection object. Next, create a Cursor object using the cursor method of the Connection object. Then, execute a SELECT statement. After that, call the fetchall() method of the cursor object to fetch the data.
Source code: Lib/sqlite3/ SQLite is a C library that provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage.
The Python SQLite module is not threadsafe. If you disable its checking then you need to ensure all code is serialized and that includes garbage collection. (My APSW module is threadsafe and also correctly handles the error message thread safety issues).
It is however safe to use multiple independent connections concurrently in the same process and I would recommend you do that. Additionally switch the database into write ahead logging mode and you should get very good performance even with lots of writing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With