pythonsqlite锁定_python – 可以在NFS文件系统上锁定sqlite文件吗?
假设有两个python脚本想要将数据写入同一个表,该表使用sqlite3模块存储在SQLite文件中. SQLite文件存储在NFS文件系统中.在
SQLite-FAQ我读到:
SQLite uses reader/writer locks to control access to the database.
[…] But use caution: this locking mechanism might not work correctly
if the database file is kept on an NFS filesystem. This is because
fcntl() file locking is broken on many NFS implementations. You should
avoid putting SQLite database files on NFS if multiple processes might
try to access the file at the same time.
这是否意味着它根本不可能或者是否有某种方法可以确保一个进程等到另一个进程完成?
INSERT并不复杂.一些:
INSERT_STATEMENT = "INSERT INTO some_table (row, col, val) VALUES (?, ?, ?)"
connection.executemany(INSERT_STATEMENT, triples)
并且插入的集合是不相交的.
还有一个问题:当两个进程尝试写入同一个表或尝试写入同一个数据库(即文件)时,是否会出现NFS问题?让每个进程在同一个数据库(文件)中创建自己的表并写入该表是否是一种解决方法?