mardi 27 octobre 2015

sqlite3: avoiding "database locked" collision

I am running two python files on one cpu in parallel, both of which make use of the same sqlite3 database. I am handling the sqlite3 database using sqlalchemy and my understanding is that sqlalchemy handles all the threading database issues within on app. My question is how to handle the access from the two different apps? One of my two programs is a flask application and the other is a cronjob which updates the database from time to time. It seems that even read only tasks on the sqlite database lock the database, meaning that if both apps want to read or write at the same time I get an error.

OperationalError: (sqlite3.OperationalError) database is locked

Lets assume that my cronjob app runs every 5min. How can I make sure that there are no collisions between my two apps? I could write some read flag into a file which I check before accessing the database, but it seems to me there should be a standard way to do this? Furthermore I am running my app with gunicorn and in principle it is possible to have multiple jobs running... so I eventually want more than 2 parallel jobs for my flask app... thanks carl

Aucun commentaire:

Enregistrer un commentaire