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
close() method is automatically invoked at the end of the block. The Connection , is a proxy object for an actual DBAPI connection. The DBAPI connection is retrieved from the connection pool at the point at which Connection is created.
SQLAlchemy includes several connection pool implementations which integrate with the Engine . They can also be used directly for applications that want to add pooling to an otherwise plain DBAPI approach.
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).
The create_engine() method of sqlalchemy library takes in the connection URL and returns a sqlalchemy engine that references both a Dialect and a Pool, which together interpret the DBAPI's module functions as well as the behavior of the database.
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.
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()
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