I am using sqlite (v2.6.0) as database backend and using sqlalchemy(v0.7.9) to operate it.
Recently I got a error OperationalError: (OperationalError) database is locked
By searching stackoverflow a possible solution is to increase the timeout of a connection. Referece: OperationalError: database is locked
But I don't know how to did that in sqlalchemy (since connection are actually controlled by it) Can someone give me a direction?
SQLAlchemy is an SQL toolkit that provides efficient and high-performing database access for relational databases. It provides ways to interact with several database engines such as SQLite, MySQL, and PostgreSQL.
Database URLs Dialect names include the identifying name of the SQLAlchemy dialect, a name such as sqlite , mysql , postgresql , oracle , or mssql . The drivername is the name of the DBAPI to be used to connect to the database using all lowercase letters.
SQLAlchemy is the ORM of choice for working with relational databases in python. The reason why SQLAlchemy is so popular is because it is very simple to implement, helps you develop your code quicker and doesn't require knowledge of SQL to get started.
Connection timeout is on the client's side, usually meaning that the client lost connection, or is unable to establish connection to a server for whatever reason (such as remote firewall is dropping the traffic or the server went down).
SQLAlchemy's create_engine()
takes an argument connect_args
which is a dictionary that will be passed to connect()
of the underlying DBAPI (see Custom DBAPI connect()
arguments). sqlite3.connect()
accepts timeout
argument, so this should work:
create_engine('sqlite:///some.db', connect_args={'timeout': 15})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With