How can I make Flask-SQLAlchemy use a self-compiled sqlite with support for usleep()?
I am using Flask 0.10.1 and Flask-SQLAlchemy 2.1 with Python 3.4.0 to provide a microservice running in Ubuntu 14.04. As database backend for my app, I'm using SQLite with default settings:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/my-database.db'
The installed version of SQLite3 is 3.8.2.
In the course of operating my service, I occasionally see the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: database is locked
The microservice does not hold any database connections for a prolonged period of time, so at first this issue looked inexplicable to me. I did some research and came across the article the SQLite lock timeout nightmare. It suggests that SQLite can be compiled without usleep() support and therefore may only try to lock the database in full-second intervals. Given that the default lock timeout for SQLite is 5 seconds we basically have 5 attempts to try a database connection before it fails. Inspection of my SQLite compile flags also reveals that HAVE_USLEEP was not set. Also, SQLAlchemy does not allow setting a different pool timeout for SQLite, since a NullPool is used. I want to substitute SQLite by a version which supports usleep() to reduce the probability of lock timeouts. How can it be done?
Aucun commentaire:
Enregistrer un commentaire