SQLAlchemy引发了QueuePool 10的大小超限10溢出,连接超时一段时间后 [英] SQLAlchemy raises QueuePool limit of size 10 overflow 10 reached, connection timed out after some time
问题描述
def create_app(config_name):
app = Flask(__ name__)
app.config.from_object (config)#include [config_name] .init_app(app)
initialize_db(app)
$ b db = SQLAlchemy()
def initialize_db app):
db.init_app(app)
SQLALCHEMY_POOL_SIZE = 100
我找到了问题所在。问题是有时数据库连接将会失去状态,导致池大小在一定的时间间隔后耗尽。
为了解决这个问题,我把MySQL服务器配置更改为查询超时,并将其设置为1秒。
如果查询没有响应1秒钟后,它会抛出异常,我添加除了在代码块调用该查询(在我的情况下,它是GET查询)块。在Except块中,我发出了回滚命令。
While using Flask-SQLAlchemy I get the error 'QueuePool limit of size 10 overflow 10 reached, connection timed out' consistently, after some time. I tried to increase connection pool size, but it only deferred the problem.
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
initialize_db(app)
db = SQLAlchemy()
def initialize_db(app):
db.init_app(app)
SQLALCHEMY_POOL_SIZE = 100
I figured out the problem. The issue was sometimes database connection was going to lost state, which is causing pool size to be Exhausted after some interval.
To fix the issue I made the MySQL server configuration change for query timeout and made it 1 second.
After 1 second if the query didn't respond it will throw Exception and I added except block in code where that query was invoked(In my case it was GET query). In the Except block, I issued rollback command.
这篇关于SQLAlchemy引发了QueuePool 10的大小超限10溢出,连接超时一段时间后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!