如何在pyodbc上使python退出时超时错误?

时间:2014-02-06 11:56:50

标签: python pyodbc

当数据库抛出超时错误时,如何让我的python脚本退出?如果我按ctrl-c手动退出,我只收到消息 - 我想让python到立即停止错误..

#!/usr/bin/python
import pyodbc
conn = pyodbc.connect("DSN=OurDSN", autocommit=True)
cursor = conn.cursor()
query = "SELECT * FROM our_table limit 100"
for row in cursor.execute(query):
    print row

错误讯息:

"Traceback (most recent call last):          
 File "./impala_test.py", line 6, in <module>
conn = pyodbc.connect("OurDSN=Hive", autocommit=True)
 pyodbc.Error: ('HY000', '[HY000] [unixODBC][Cloudera][HiveODBC] (34) Error from Hive:    EAGAIN (timed out). (34) (SQLDriverConnect)')"

1 个答案:

答案 0 :(得分:0)

默认情况下,

pyodbc的query timeout处于禁用状态。尝试将其设置为您想要的值吗?