"ping" not reconnecting in Python MySQLdb client interface
nagle at animats.com
Sun Feb 3 18:03:41 CET 2008
JJohn Nagle wrote:
> I have some long-running Python programs that can be idle
> for hours, and, of course, the MySQL connection times out.
> So I call
> at the beginning of a new request cycle. This should
> reestablish the connection, but it doesn't.
> I suspect that MySQL has auto-reconnect turned off, but doesn't document
That seems to be the case. MySQLdb.connect turns off auto-reconnect, and
doesn't document "ping".
I'm currently trying this:
if db : # if previously attached
db.ping() # test connection
except MySQLdb.OperationalError, message: # loss of connection
db = None # we lost database connection
if db is None : # if no valid database handle
db = MySQLdb.connect(...) # connect to database
which is a bit ugly.
More information about the Python-list