Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
latorc committed Dec 15, 2023
1 parent 605444b commit 5666186
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@
def main(cfg:str):
the_config = config.Config(cfg) # 初始化配置

common.logger().info("正在创建WechatFerry实例...")
wcfw = wcf_wrapper.WcfWrapper()

# 在退出信号和Ctrl+C信号时,清理wcf并退出, 否则可能导致微信客户端异常
def handler(sig, frame):
logging.info("进行退出清理...")
wcfw.__del__()
exit(0)
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
try:
common.logger().info("正在创建WechatFerry实例...")
wcfw = wcf_wrapper.WcfWrapper()

# 在退出信号和Ctrl+C信号时,清理wcf并退出, 否则可能导致微信客户端异常
def handler(sig, frame):
logging.info("进行退出清理...")
wcfw.__del__()
exit(0)
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)

# 创建机器人并运行
common.logger().info("启动微信机器人...")
bot = chatbot.Chatbot(the_config, wcfw)
common.logger().info("开始运行")
bot.start_main_loop()
# 创建机器人并运行
common.logger().info("启动微信机器人...")
bot = chatbot.Chatbot(the_config, wcfw)
common.logger().info("开始运行")
bot.start_main_loop()

except Exception as e:
common.logger().fatal("程序发生错误, 即将退出: %s", common.error_trace(e))
return


if __name__ == "__main__":
Expand Down

0 comments on commit 5666186

Please sign in to comment.