1
瓶 的Python 2.7 的Postgres 9 的Ubuntu 14.04烧瓶SQLAlchemy的TimeoutError
我使用的瓶和SQLAlchemy的,经过连续15个HTTP请求,我得到:
大小5溢流槽10的QueuePool达到上限,连接超时,超时30
然后服务器停止响应:
非常类似:
我没有会话引擎,按我的理解瓶-SQLAlchemy中应照顾它。 我需要配置什么以支持更多的会话并定期清理现有的会话。
app.py
import models
api_app = Flask(__name__)
api_app.config.from_pyfile(settings.celery_config)
db = SQLAlchemy(api_app)
@api_app.teardown_appcontext
def shutdown_session(exception=None):
try:
db.session.close()
except AttributeError,e:
print str(e)
except Exception,e:
print api_app.name
print str(e)
@api_app.route('/api/1.0/job/<string:ref>/')
def get_job_by_id(ref):
"""
:param id:
:return:
"""
try:
if request.method == 'GET':
job = models.Job.query.filter(models.Job.reference == ref)
if job:
job_ = job.all()
if len(job_) == 1:
return jsonify(job_[0].serialize())
resp = Response(status=404, mimetype='application/json')
return resp
else:
resp = Response(status=405, mimetype='application/json')
return resp
except Exception,e:
print str(e)
resp = Response(status=500, mimetype='application/json')
return resp
models.py
from api_app import db
class Job(db.Model, AutoSerialize, Serializer):
__tablename__ = 'job'
__public__ = ('status','description','reference')
id = Column(Integer, primary_key=True, server_default=text("nextval('job_id_seq'::regclass)"))
status = Column(String(40), nullable=False)
description = Column(String(200))
reference = Column(String(50))
def serialize(self):
d = Serializer.serialize(self)
del d['id']
return d
尝试了db.session.remove(),重启应用相同的问题 – spicyramen
尝试设置值:https://pythonhosted.org/Flask-SQLAlchemy/config.html,现在工作:api_app.config ['SQLALCHEMY_POOL_SIZE'] = 100 – spicyramen
@spicyramen我编辑我的文章并添加您的评论。谢谢 –