有没有办法在Python中显式获取sqlite3数据库的锁?
解决方法:
显式锁定数据库的方法是启动事务,如documentation中所述:
When a database is accessed by multiple connections, and one of the processes modifies the database, the SQLite database is locked until that transaction is committed.
import sqlite3
con = sqlite3.connect(...)
...
with con:
# Database is locked here
另请注意,某些事务默认情况下发生在implictly:
By default, the sqlite3 module opens transactions implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE), and commits transactions implicitly before a non-DML, non-query statement (i. e. anything other than SELECT or the aforementioned).
标签:python,sqlite3
来源: https://codeday.me/bug/20190610/1208716.html