SQLAlchemy raises QueuePool limit of size 10 overflow 10 reached, connection timed out after some time

和自甴很熟 提交于 2019-12-06 03:22:47

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.

I just had this issue.


My situation

  • I have not yet launched my website, and so I am spending almost all of my time interacting with the local version, which is being run from PyCharm (i.e. on my computer), and so I only noticed the error on my local version of the site, and I didn't even try to see if it would also occur on the PythonAnywhere-hosted production version of the site.
  • I am using a MySQL database.
  • IIRC I first noticed the problem when I started running frequent (every 10 seconds) API calls from my front-end JavaScript.
  • I had debug=False in my app.run(), so it wasn't being caused by debug=True, which is something suggested elsewhere.

How I fixed it

The problem went away when I got rid of threaded=True in my app.run().

  • So, previously it looked like this:
    • app.run(debug=False, threaded=True)
  • and I changed it to look like this:
    • app.run(debug=False)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!