求助supervisord+python+ngnix 重启supervisord后一段时间网站报错
如题 小弟用supervisord管理的python进程 每次重启supervisord后网站可以访问 一切正常 但是过3~5分钟后就报错
详细错误如下:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/tornado/web.py", line 1141, in _when_complete
callback()
File "/usr/local/lib/python2.7/site-packages/tornado/web.py", line 1162, in _execute_method
self._when_complete(method(*self.path_args, **self.path_kwargs),
File "/data/www/jsyxsh/handlers/home.py", line 13, in get
self.render('home/index.html', products=products)
File "/usr/local/lib/python2.7/site-packages/tornado/web.py", line 538, in render
html = self.render_string(template_name, **kwargs)
File "/usr/local/lib/python2.7/site-packages/tornado/web.py", line 645, in render_string
return t.generate(**namespace)
File "/usr/local/lib/python2.7/site-packages/tornado/template.py", line 273, in generate
return execute()
File "home/index_html.generated.py", line 35, in _tt_execute
for news in handler.news: # home/_layout.html:49
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2216, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2231, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 662, in execute
params)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 761, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 828, in _execute_context
None, None)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception
exc_info
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 163, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 822, in _execute_context
conn = self._revalidate_connection()
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 239, in _revalidate_connection
"Can't reconnect until invalid "
StatementError: Can't reconnect until invalid transaction is rolled back (original cause: InvalidRequestError: Can't reconnect until invalid transaction is rolled back) 'SELECT articles.id AS articles_id, articles.title AS articles_title, articles.content AS articles_content, articles.category_id AS articles_category_id, articles.author_id AS articles_author_id, articles.post_time AS articles_post_time \nFROM articles ORDER BY articles.id DESC \n LIMIT %s, %s' [immutabledict({})]
请各位大神帮看看是哪里不对
小弟初学python 不是很了解 分不多了 全给了 求好心大神帮帮忙吧
[解决办法]
应该是你的代码的问题,和supervisord没有关系,看看tornado,SQLAlchemy,和数据库的连接问题吧。
看看这样搞,要对错误进行处理
try:
session.commit()
except:
session.rollback()