Description
Documentation
https://docs.python.org/3/library/sqlite3.html#module-functions:
check_same_thread (bool) – If True (default), ProgrammingError will be raised if the database connection is used by a thread other than the one that created it. If False, the connection may be accessed in multiple threads; write operations may need to be serialized by the user to avoid data corruption. See threadsafety for more information.
and
Serialized: In serialized mode, SQLite can be safely used by multiple threads with no restriction.
... The serialized mode is default on both Mac and Windows so we can probably skip validating that. I did like mentioning the user needs to serialize the writes. They could use one thread for writing only or use locking. So, I just said to serialize.
the code:
cpython/Modules/_sqlite/connection.c
Lines 1698 to 1714 in c141748
the issue:
the sqlite
originally itself does not have this check_same_thread
option, and
https://sqlite.org/c3ref/c_config_covering_index_scan.html#sqliteconfigserialized:
SQLITE_CONFIG_SERIALIZED
There are no arguments to this option. This option sets the threading mode to Serialized. In other words, this option enables all mutexes including the recursive mutexes on database connection and prepared statement objects. In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1) the SQLite library will itself serialize access to database connections and prepared statements so that the application is free to use the same database connection or the same prepared statement in different threads at the same time. If SQLite is compiled with the SQLITE_THREADSAFE=0 compile-time option then it is not possible to set the Serialized threading mode and sqlite3_config() will return SQLITE_ERROR if called with the SQLITE_CONFIG_SERIALIZED configuration option.
according sqlite
itself said the SQLite library will itself serialize access to database connections and prepared statements so that the application is free to use the same database connection or the same prepared statement in different threads at the same time.
, why does python sqlite3 need this check_same_thread option? and the sqlite3.threadsafety
returned also is 3
the document may statement clear it
Metadata
Metadata
Assignees
Projects
Status