Testing MySQLdb connection object

Discussion in 'Python' started by Bernard Lebel, Jan 9, 2006.

  1. 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
     
    Bernard Lebel, Jan 9, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Roderick

    Failing connection with MySQLdb on Mac OS X

    Stephen Roderick, May 29, 2004, in forum: Python
    Replies:
    0
    Views:
    305
    Stephen Roderick
    May 29, 2004
  2. Brian van den Broek
    Replies:
    3
    Views:
    874
    Jeremy Bowers
    Apr 3, 2005
  3. Brian van den Broek
    Replies:
    2
    Views:
    408
    Brian van den Broek
    Apr 5, 2005
  4. John Nagle
    Replies:
    4
    Views:
    1,754
    Dennis Lee Bieber
    Jun 12, 2010
  5. Romaric DEFAUX
    Replies:
    0
    Views:
    290
    Romaric DEFAUX
    Jan 20, 2011
Loading...

Share This Page