V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
larkifly
V2EX  ›  Python

求使用 flask-sqlalchemy 的正确姿势,最近总报 Too many connections 错误, SQLALCHEMY_POOL_SIZE=5

  •  
  •   larkifly · 2016-04-22 15:39:41 +08:00 · 6170 次点击
    这是一个创建于 2897 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如题,已经设置了 SQLALCHEMY_POOL_SIZE=5 ,依然无法解决。

    mysql> show global status like '%connect%';
    +--------------------------+-------+
    | Variable_name | Value |
    +--------------------------+-------+
    | Aborted_connects | 8 |
    | Connections | 374 |
    | Max_used_connections | 21 |
    | Ssl_client_connects | 0 |
    | Ssl_connect_renegotiates | 0 |
    | Ssl_finished_connects | 0 |
    | Threads_connected | 5 |
    +--------------------------+-------+
    6 条回复    2016-04-26 09:55:47 +08:00
    myyou
        1
    myyou  
       2016-04-22 16:12:55 +08:00
    你用 db.session.close()了没?
    liyj144
        2
    liyj144  
       2016-04-22 16:31:48 +08:00
    show variables like "%max_connections%"; 查看最大连接数,我怀疑是 mysql 配置的最大连接数太小, 然后 show processlist; 看看连接情况。
    larkifly
        3
    larkifly  
    OP
       2016-04-24 23:56:00 +08:00
    @myyou 没有,如果每次都 db.session.close(),那是不是要每次使用的时候,都得 db = SQLAlchemy(app)初始化一下连接???
    myyou
        4
    myyou  
       2016-04-25 12:52:28 +08:00
    @larkifly 不需要,你只是关闭连接回话( session ),和 SQLAlchemy(app)初始没关系。
    larkifly
        5
    larkifly  
    OP
       2016-04-25 17:36:31 +08:00
    @myyou 哦,明白了,那么调用 Table.query.filter_by 这样的 select 语句时,需要关闭吗?
    myyou
        6
    myyou  
       2016-04-26 09:55:47 +08:00
    @larkifly 不需要
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1129 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:46 · PVG 02:46 · LAX 11:46 · JFK 14:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.