开发者

python database drivers timeout

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜