Sql Alchemy QueuePool limit overflow

You can manage pool size by adding parameters pool_size and max_overflow in function create_engine

engine = create_engine("mysql://" + loadConfigVar("user") + ":" + loadConfigVar("password") + "@" + loadConfigVar("host") + "https://stackoverflow.com/" + loadConfigVar("schema"), 
                        pool_size=20, max_overflow=0)

Reference is here

You don’t need to close the session, but the connection should be closed after your transaction has been done.
Replace:

rescount = DBSession.connection().execute("select resource_id,count(resource_id) as total FROM resourcestats")

By:

connection = DBSession.connection()
try:
    rescount = connection.execute("select resource_id,count(resource_id) as total FROM resourcestats")
    #do something
finally:
    connection.close()

Reference is here

Also, notice that mysql’s connection that have been stale is closed after a particular period of time (this period can be configured in MySQL, I don’t remember the default value), so you need passing pool_recycle value to your engine creation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)