Python database timeout

This is a general question about all python database drivers, but if you answer a specific driver (pyodbc, psycopg2, pymysql, mysqldb, etc.), it will still be useful.

As soon as I have a connection and a cursor, is there a way (API) to check the connection, whether or not has a timeout, without trying to execute the command in this way without reading / writing through the socket?

+4
source share
1 answer

Psycopg2 has an attribute in cursor and connection objects with the name "closed".

For example, to check if the cursor is open:

connection = psycopg2.connect (...) cursor = connection.cursor() if cursor.closed: print('the connection is closed') else: ... 
+1
source

Source: https://habr.com/ru/post/1369568/


All Articles