From 95c7ee717b9799af89b7ae9569bd5450858457ac Mon Sep 17 00:00:00 2001 From: tursom Date: Sun, 3 Mar 2024 02:23:07 +0800 Subject: [PATCH] safety close log file --- sample.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sample.py b/sample.py index 9873a69..69530a8 100644 --- a/sample.py +++ b/sample.py @@ -41,8 +41,14 @@ def handle_sighup(signum, frame): global room_status_log for room_id in log_files: - log_files[room_id].close() - room_status_log.close() + try: + log_files[room_id].close() + except Exception as e: + logger.exception(f"close log_files[{room_id}] failed with {e}") + try: + room_status_log.close() + except Exception as e: + logger.exception(f"close room_status_log failed with {e}") log_files = {} room_status_log = open("logs/room_status.jsonl", "a", encoding="utf-8")