Massimo Fazzolari Massimo Fazzolari - 1 year ago 278
Python Question

Flask-SQLAlchemy TimeoutError

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 Source

Flask-SQLAlchemy manages the connection pool for you, so in general, it should not be necessary to do this. However, there are some instances in which it cannot control this, specifically if you are executing queries outside a request context or using with app.app_context() somewhere.

When I paired Flask-SQLAlchemy with apscheduler, I found myself having to explicitly close sessions in the jobs the scheduler executed, or after several hours of running I would get this error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download