Flask-SQLAlchemy TimeoutError

2024/10/8 14:44:52

My backend configuration is :

  • Ubuntu 12.04
  • Python 2.7
  • Flask 0.9
  • Flask-SQLAlchemy
  • Postgres 9.2

I've got this error message:

TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30

Do I need to close explicitly the db.session? Shouldn't be the connection back to pool when session goes out of scope?

Answer

This could happen if you are using debug=True in your application and you have loaded several pages or API endpoints which errored out.

The reason is that running the debug version of the app keeps a live debugger open in the error page. This live debugger keeps around all the resources from processing the request, so that you can examine them. This means that the database connection can't be recycled.

You shouldn't use debug mode for the production version of your app (apart from problems like this it is a security risk), and the debugger often won't work anyway (it is designed to work with the flask test server, not with gunicorn). Therefore in prod the solution is to turn off debug.

If you have this problem in dev using debug mode - this is a limitation. You shouldn't be hitting the dev server so hard, or you can increase the limit. Be aware that 15 connections are usually plenty to serve a large number of concurrent requests when they are being recycled properly. It's only in debug that they tend to run out.

https://en.xdnf.cn/q/70114.html

Related Q&A

Making saxon-c available in Python

I have just read that Saxon is now available for Python, and thats just great fun and good, but can anyone write a tutorial on how to make it available for Python/Anaconda/WingIDE or similar? I am use…

How to include multiple interactive widgets in the same cell in Jupyter notebook

My goal is to have one cell in Jupyter notebook displaying multiple interactive widgets. Specifically, I would like to have four slider for cropping an image and then another separate slider for rotati…

SWIG - Problem with namespaces

Im having trouble getting the following simple example to work with SWIG 1.3.40 (and I also tried 1.3.31). The Foo structure comes through as a Python module as long as I dont wrap it in a namespace, b…

Django access to subclasses items from abstract class

class Animal(models.Model):....class Meta:abstract = Trueclass Cat(models.Model, Animal):...class Dog(models.Model, Animal):....I want to be able to return all instances of querysets of all the subclas…

Django BinaryField retrieved as memory position?

Ive written a short unit test with the following code:my_object = MyObject() my_object.data = b12345my_object.save() saved_object = MyObject.objects.first()assert saved_object.data == my_object.datawhe…

difflib.SequenceMatcher isjunk argument not considered?

In the python difflib library, is the SequenceMatcher class behaving unexpectedly, or am I misreading what the supposed behavior is?Why does the isjunk argument seem to not make any difference in this…

PyCharm Code Folding/Outlining Generates Wrong Boundaries

Im having a very frustrating issue with PyCharm in that it does not want to properly outline the code so that blocks fold correctly. Ive looked all over the place and couldnt find any help with this pa…

How to clear the conda environment variables?

While I was setting an environment variable on a conda base env, I made an error in the path that was supposed to be assigned to the variable. I was trying to set the $PYSPARK_PYTHON env variable on th…

Create duplicates in the list

I havelist = [a, b, c, d]andnumbers = [2, 4, 3, 1]I want to get a list of the type of:new_list = [a, a, b, b, b, b, c, c, c, d]This is what I have so far:new_list=[] for i in numbers: for x in list: f…

cxfreeze aiohttp cannot import compat

Im trying to use cx_freeze to build a binary dist for an web application written in Python 3 using the aiohttp package.Basically I did:cxfreeze server.pyand got a dist outputBut when running the ./serv…