So our python program is running into these errors _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
. The problem is that the program accesses the db, hen does a lot of crawling to come back with the results after the mysql connection timeout
... and then its too late.
By logic there are 2 solutions
- increase
mysql connection timeout
but this is no option - have python check for an open connection, and if closed then re-open it
Some solutions have been found and sound clear possible solution and here about closing and opening cursors.
However we are using models from django .. and I dont know where to implement logic for a check for a connection and reconnect of the connectin is lost
check.
question: Where and how can I implement the described logic to re-connect to a lost db connection when using models? (is there some kind of INIT or CONNECT event to access)
Sample code
from django.db import models
class Domain(models.Model):
name = models.CharField(max_length=100)
domain = models.CharField(max_length=100, blank=True, null=True)