【发布时间】:2013-09-07 04:12:37
【问题描述】:
有一个运行良好的长时间运行的进程。在我手动提交事务的地方添加 transaction.commit() 后开始出现 (2006 'MySQL server has gone away') 错误。
之前(效果很好):
DBObject.objects.get(id = 1)
之后:(在晚上闲置 8 小时后得到错误)
注意:我需要像这样刷新它以避免获取过时的数据。
flush_transaction()
DBObject.objects.get(id = 1)
在哪里
@transaction.commit_manually
def flush_transaction():
"""
Flush the current transaction so we don't read stale data
Use in long running processes to make sure fresh data is read from
the database. This is a problem with MySQL and the default
transaction mode. You can fix it by setting
"transaction-isolation = READ-COMMITTED" in my.cnf or by calling
this function at the appropriate moment
"""
transaction.commit()
据我了解,我正在切换到 commit_manually 但似乎我也失去了 django 的自动重新连接。
除了增加mysql端的wait_timeout,还有什么好的处理方法吗?
【问题讨论】:
标签: python mysql django python-2.7 transactions