给定以下 Python 代码:
# Use impyla package to access Impala
from impala.dbapi import connect
import logging
def process():
conn = connect(host=host, port=port) # Mocking host and port
try:
cursor = conn.cursor()
# Execute query and fetch result
except:
loggin.error("Task failed with some exception")
finally:
cursor.close() # Exception here!
conn.close()
与 Impala 的连接已创建。cursor.close()
但是由于 Impala 超时而出现异常。
鉴于潜在异常,关闭cursor
and的正确方法是什么?conn