How to check if a MySQL connection is open in Python?
问题 I am using MySQLdb (http://mysql-python.sourceforge.net/). It seems that connection.open and connection.sqlstate() do not work for me. Below is the code: def open(self): #TODO: check the connection's status # self.__conn.open OR self.__conn.sqlstate() try: print "sqlstate:"+str( self.__conn.sqlstate() ) print "open?"+str( self.__conn.open ) return "00000" == self.__conn.sqlstate() except Exception as e: print "Exception while checking MYSQL Connection:"+str(e) return False But when I ran