How to check if a MySQL connection is closed in Python?

Question:

The question says everything. How can I check if my MySQL connection is closed in Python?

I’m using MySQLdb, see http://mysql-python.sourceforge.net/

Asked By: Kent

||

Answers:

The Connection.open field will be 1 if the connection is open and 0 otherwise. So you can say

if conn.open:
    # do something
Answered By: Eli Courtwright
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.