python sqlite3模块使用
-
sqlite3.connect(filename, check_same_thread=False)
1. check_same_thread=False的作用: python sqlite3的线程模式默认串行, 如果需要再多线程中用一个句柄,需要加此参数,否则将出现如下错误:- sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 65984 and this is thread id 61236.
2. 同时也需要加互斥锁, 否则在
execute
时偶现(多线程同时execute
)地会报如下错误:- cannot commit - no transaction is active