我有一个返回TimeOut的Sql Alchemy应用程序:
TimeoutError:达到大小为5的QueuePool限制溢出10,连接超时,超时30
我在另一篇文章中读到,当我不关闭会话时会发生这种情况,但我不知道这是否适用于我的代码:
我在init.py中连接到数据库:
from .dbmodels import (
DBSession,
Base,
engine = create_engine("mysql://" + loadConfigVar("user") + ":" + loadConfigVar("password") + "@" + loadConfigVar("host") + "/" + loadConfigVar("schema"))
#Sets the engine to the session and the Base model class
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Run Code Online (Sandbox Code Playgroud)
然后在另一个python文件中我收集了两个函数中的一些数据,但是使用了我在init.py中初始化的DBSession:
from .dbmodels import DBSession
from .dbmodels import resourcestatsModel
def getFeaturedGroups(max = 1):
try:
#Get the number of download per resource
transaction.commit()
rescount = DBSession.connection().execute("select resource_id,count(resource_id) as total FROM resourcestats")
#Move the data to an array
resources …Run Code Online (Sandbox Code Playgroud)