[Twisted-Python] Consensus on how to handle "MySQL server has gone away"

E S electric.or.sharp at gmail.com
Tue Oct 2 13:09:29 EDT 2012

I have a service running that occasionally connects to a MySQL
database. When there is no activity on it for some time, I eventually
get the the error

_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')

I have found a few posts on this group related to this issue


as well as some tickets on the twisted homepage:


I have also seen this referenced as a potential fix:


I currently have the cp_reconnect parameter set to True, but it does
not appear to be doing the job. I don't really see much consensus on
how to properly handle this issue. Some people seem to think that the
cp_reconnect parameter should take care of it for you, other people
say that cp_reconnect is only part of the solution and that you have
to write your own error handling.

I realize that I could increase the value of MySQL's wait_timeout
parameter, but I would rather have the twisted code detect and handle
the situation. So, how does one do that?


More information about the Twisted-Python mailing list