Testing MySQLdb connection object

B

Bernard Lebel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top