Serializing Sqlite3 in Python Serializing Sqlite3 in Python sqlite sqlite

Serializing Sqlite3 in Python


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.


The sqlite page http://www.sqlite.org/threadsafe.html says, "The default mode is serialized." Have you tested it and found this to not be true?

Edit:


If it fails to work, maybe ctypes? I have no idea if this would have any effect on the loaded sqlite module. I guess I sort of suspect it doesn't; as I'd imagine the sqlite3_initialize() function is likely called when the module is loaded? Or maybe only when you create a database object?

http://www.sqlite.org/c3ref/config.html

>>> import sqlite3>>> import ctypes>>> from ctypes.util import find_library>>> sqlite_lib = ctypes.CDLL(find_library('sqlite3'))>>> sqlite_lib.sqlite3_config(3) # http://www.sqlite.org/c3ref/c_abort.html0   # no error....>>>