Tomek C.
Tomek C.

Reputation: 667

MariaDB check connection state in python

Does the python MariaDB connector has api to check the connection state similar to is_connected in python-mysql or any other way to check the connection state.

Upvotes: 3

Views: 2142

Answers (1)

Georg Richter
Georg Richter

Reputation: 7496

MariaDB Connector/Python doesn't have is_connected() method, but you can check connection status with ping() method, e.g.

import mariadb

def is_connected(connection):
    try:
        connection.ping()
    except:
        return False
    return True

Upvotes: 5

Related Questions