开发者

python database drivers timeout

开发者 https://www.devze.com 2023-03-31 19:27 出处:网络
This is a generic question about all python database drivers but if you an answer for a specific driver (pyodbc, psycopg2, pymysql, mysqldb, etc.) would be useful anyway.

This is a generic question about all python database drivers but if you an answer for a specific driver (pyodbc, psycopg2, pymysql, mysqldb, etc.) would be useful anyway.

Once I have a connection and cursor, is there a way (an API) to check the connection has or has n开发者_Go百科ot timeout without attempting to execute a command thus without reading/writing through the socket?


In psycopg2, there is an attribute in both the cursor and connection objects named "closed".

For example, to check if your cursor still is open:

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

精彩评论

暂无评论...
验证码 换一张
取 消