Commit 54268321 by 周杭

异常处理优化

1 parent f9a5c6b7
...@@ -110,13 +110,18 @@ def get_connection(): ...@@ -110,13 +110,18 @@ def get_connection():
def execute_sql(sql): def execute_sql(sql):
conn = get_connection() try:
cursor = conn.cursor() conn = get_connection()
cursor.execute(sql) cursor = conn.cursor()
conn.commit() cursor.execute(sql)
cursor.close() conn.commit()
conn.close() log.info("sql 执行结束")
log.info("sql 执行结束") except Exception as msg:
log.error("sql执行Exception: " + str(msg))
finally:
cursor.close()
conn.close()
def generate_random_filename(): def generate_random_filename():
timestamp = int(time.time()) # 获取当前时间戳 timestamp = int(time.time()) # 获取当前时间戳
...@@ -465,6 +470,6 @@ def consume_kafka(): ...@@ -465,6 +470,6 @@ def consume_kafka():
log.info("handle_process耗时:"+str(end_time-start_time)) log.info("handle_process耗时:"+str(end_time-start_time))
except Exception as e: except Exception as e:
log.error("ocr consumer Exception: " + str(e)) log.error("ocr consumer Exception: " + str(e))
finally: # finally:
# 关闭消费者 # # 关闭消费者
consumer.close() # consumer.close()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!