Testing MySQLdb connection object

Bernard Lebel 3dbernard at gmail.com
Mon Jan 9 18:05:03 EST 2006


Hello,

First, this is my first post on this list!
A little about myself: I'm the lead technical director in a 3D
animation studio, in Montreal. A lot of the Python code I write is to
be used in an application that embeds Python, that is, Softimage|XSI.
Right now I'm re-writing the render farm software that runs on render
nodes, in this project is what made me learn Python in the first
place. My first question is related to that. :-)


Using the MySQLdb module, I create a connection object with a
database. It might happen that the connection is not used for a long
period of time and becomes obsolete, or the connection may simply
close for various reasons.

I'd like to write a safety procedure so that before launching a query
or performing any database operation (like commit, fetch and such),
the procedure checks if the connection object is still working. In
case it is not, it would attempt to create a new one.

I know I could send my query and catch exceptions in order to find
out, but I was wondering if there was something a little more
dedicated to this task that I could try. I have looked into the ping()
method, but it seems to always return None, wich I'm not sure how to
interpret.


Any suggestion is welcomed.


Thanks
Bernard



More information about the Python-list mailing list