Is there a way to explicitly acquire a lock on a sqlite3 database in Python?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The way to explicitly lock the database is start a transaction as explained in the documentation:
One way to initiate a transaction is use the connection as a context manager:
Also note that some transactions happen implictly by default:
From the sqlite FAQ, "Can multiple applications or multiple instances of the same application access a single database file at the same time?":
Whether or not you use the
with connection
construct, many processes can read from by only one can write to the database at any given time.We can use multi process commands to lock the DB write and read process . I am using following commands and its working fine . from multiprocessing import Lock l.Lock() l.acquire() Read/Write DB l.release()