I am writing a server which provide a service by query MySQL database. Everything goes fine, except when run one or two days the connection will go away. The error code is (2600, MySQL has gone away)
I try to wrap the cursor object by:
def cursor(self):
try:
return self.connection.cursor()
except:
self.connection = MySQLdb.connect(**self.kwargs)
return self.connection.cursor()
This seems not work, I still got error while I the cursor from this wrapper class when I call cursor.execute(..).
Any idea that I can keep consistent connection?