I am using Python and mySQL, and there is a long lag between queries. As a result, I get an \'MySQL connection has gone away\' error, that is wait_timeout is exceeded.
I had the same problem and wanted to wrap the exception to capture it but instead I solved it by using the following.
Before calling the execute, call
self.con.ping(TRUE)
http://www.neotitans.com/resources/python/mysql-python-connection-error-2006.html http://mysql-python.sourceforge.net/MySQLdb.html
I can no longer find the original source material I found this out from, but this solved the problem immediately.