SQLAlchemy引发了QueuePool 10的大小超限10溢出,连接超时一段时间后 [英] SQLAlchemy raises QueuePool limit of size 10 overflow 10 reached, connection timed out after some time

查看:6489
本文介绍了SQLAlchemy引发了QueuePool 10的大小超限10溢出,连接超时一段时间后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Flask-SQLAlchemy的时候,在一段时间后,我得到了一个错误'QueuePool limit 10 size overflow 10,connected timed out'。我试图增加连接池大小,但它只推迟了这个问题。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆