Kent
Kent

Reputation: 423

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

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/

Upvotes: 28

Views: 25421

Answers (1)

Eli Courtwright
Eli Courtwright

Reputation: 193321

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

if conn.open:
    # do something

Upvotes: 34

Related Questions