Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase connection timeout using sqlalchemy with sqlite in python

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?

like image 556
user1817188 Avatar asked Feb 25 '13 10:02

user1817188


People also ask

Can I use SQLAlchemy with SQLite?

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.

What is Dbapi in SQLAlchemy?

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.

Is SQLAlchemy worth using?

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.

What is connection timeout?

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


1 Answers

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})
like image 131
Audrius Kažukauskas Avatar answered Oct 18 '22 07:10

Audrius Kažukauskas