How to increase connection timeout using sqlalchemy with sqlite in python

user1817188 picture user1817188 · Feb 25, 2013 · Viewed 9k times · Source

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?

Answer

Audrius Kažukauskas picture Audrius Kažukauskas · Feb 25, 2013

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})