safety close log file

This commit is contained in:
tursom 2024-03-03 02:23:07 +08:00
parent 9fcaa5df25
commit 95c7ee717b

View File

@ -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")