Nazmul Hasan
Nazmul Hasan

Reputation: 7040

Sql Alchemy connection time Out

I am using sqlalchemy with MySQL, and executing query with sql expression. When executing a number of query then it time out. I found an answer but it is not clear to me. Please, any one can help me?

TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30

Upvotes: 46

Views: 33006

Answers (2)

Aaren Shar
Aaren Shar

Reputation: 568

In multi-thread mode, if your concurrent request num is much more than the db connection pool size, it will throw the Queue Pool limit of size 5 overflow 10 reached error. try with this:

engine = create_engine('mysql://', convert_unicode=True, 
pool_size=20, max_overflow=100)

to add the pool size

Add: the method above is not a correct way. The actual reason is that db connection pool is used up, and no other available connection. The most probably situation is you miss to release connection. For example:

@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()

Upvotes: 13

Greg
Greg

Reputation: 47164

Whenever you create a new session in your code, make sure you close it. Just call session.close()

When I got this error I thought I was closing all of my sessions, but I looked carefully and there was one new method where I wasn't. Closing the session in that method fixed this error for me.

Upvotes: 56

Related Questions