当数据库抛出超时错误时,如何使我的python脚本退出?我只有在手动退出时才会收到消息 - 我想在错误上立即将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)')"
pyodbc的查询超时是默认情况下禁用的。尝试将其设置为您想要的值?