Question

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?

Was it helpful?

Solution

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})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top