Aggiungi Connection.timeout
assegnazione variabile al tuo codice. Il valore predefinito è 0
(timeout disabilitato), previsto in secondi.
import pyodbc
import time
connString = 'SERVER=dbserver;PORT=1433;DATABASE=db;UID=dbuser;PWD=dbpwd;' + \
'DRIVER=FreeTDS'
cnxn = pyodbc.connect(connString)
cnxn.timeout = 3
cursor = cnxn.cursor()
t1 = time.time()
cursor.execute("SELECT MAX(Qty) FROM big_table WHERE ID<10000005")
print cursor.fetchone()
t2 = time.time()
print t2-t1
cursor.execute("WAITFOR DELAY '00:00:30'")
print 'OK'