python - django transaction.commit_manually leads to 'MySQL server has gone away' -
have long running process worked fine. started getting (2006 'mysql server has gone away') error after adding transaction.commit() manually commit transaction.
before (works great):
dbobject.objects.get(id = 1)
after: (getting error after idle 8 hours of nothing process @ night)
note: need flush avoid getting stale data.
flush_transaction() dbobject.objects.get(id = 1)
where
@transaction.commit_manually def flush_transaction(): """ flush current transaction don't read stale data use in long running processes make sure fresh data read database. problem mysql , default transaction mode. can fix setting "transaction-isolation = read-committed" in my.cnf or calling function @ appropriate moment """ transaction.commit()
as understand, i'm switching commit_manually seems i'm losing django's auto reconnect.
other increasing wait_timeout on mysql side, there way of handing this?
the problem switching commit_manual mode. seemed not closing connection properly. read more django , database connection.
what did solve issue closing db connection manually , trying query again.
to manually close connection used
from django import db db.close_connection()
hope helpful
Comments
Post a Comment