Date: 2006-12-29 08:17:40 -0700 (Fri, 29 Dec 2006)
New Revision: 2166
Another bugfix by Dan Pascu <dan@...> for MySQL errors 2006 and 2013 (SERVER_GONE, SERVER_LOST).
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-12-28 20:55:44 UTC (rev 2165)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-12-29 15:17:40 UTC (rev 2166)
@@ -78,7 +78,19 @@
def _executeRetry(self, conn, cursor, query):
- while 1:
+ # When a server connection is lost and a query is attempted, most of
+ # the time the query will raise a SERVER_LOST exception, then at the
+ # second attempt to execute it, the mysql lib will reconnect and
+ # succeed. However is a few cases, the first attempt raises the
+ # SERVER_GONE exception, the second attempt the SERVER_LOST exception
+ # and only the third succeeds. Thus the 3 in the loop count.
+ # If it doesn't reconnect even after 3 attempts, while the database is
+ # up and running, it is because a 5.0.x (or newer) server is used
+ # which no longer permits autoreconnects by default. In their case a
+ # reconnect flag must be set when making the connection to indicate
+ # that autoreconnecting is desired and the python-mysqldb module
+ # doesn't set this flag.
+ for c in range(0, 3):
# For MysqlDB 1.2.1 and later, we go
@@ -88,7 +100,9 @@
except MySQLdb.OperationalError, e:
- if e.args == 2013: # SERVER_LOST error
+ if e.args in (2006, 2013): # SERVER_GONE or SERVER_LOST error
+ if c == 2:
+ raise OperationalError(ErrorMessage(e))
self.printDebug(conn, str(e), 'ERROR')
Get latest updates about Open Source Projects, Conferences and News.