Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MariaDB check connection state in python

Tags:

python

mariadb

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.

like image 826
Tomek C. Avatar asked May 30 '26 02:05

Tomek C.


1 Answers

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
like image 57
Georg Richter Avatar answered May 31 '26 17:05

Georg Richter