Tambahkan Connection.timeout
penugasan variabel ke kode Anda. Default ke 0
(batas waktu dinonaktifkan), diharapkan dalam hitungan detik.
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'