This commit is contained in:
CakeCN
2026-01-08 20:32:29 +08:00
2 changed files with 315 additions and 96 deletions

View File

@@ -43,8 +43,9 @@ try:
original_excepthook = sys.excepthook
def custom_excepthook(exc_type, exc_value, exc_traceback):
"""全局异常钩子,捕获所有未处理的异常"""
if exc_type.__name__ in ['OSError', 'IOError'] and 'Bad file descriptor' in str(exc_value):
# 处理 Bad file descriptor 错误,不导致服务器宕机
error_str = str(exc_value)
if exc_type.__name__ in ['OSError', 'IOError'] and any(msg in error_str for msg in ['Bad file descriptor', 'Socket operation on non-socket', 'Operation on closed file']):
# 处理各种socket错误不导致服务器宕机
if not is_duplicate_error(exc_value):
print(f"[Global Error Handler] {exc_type.__name__}: {exc_value}")
print("[Traceback]")