正常に機能する長時間実行プロセスがあります。手動でトランザクションをコミットする 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を増やす以外に、これを処理する良い方法はありますか?