防止服务器宕机 : Socket operation on non-socket 错误不会导致服务器崩溃
This commit is contained in:
@@ -48,8 +48,9 @@ try:
|
|||||||
|
|
||||||
def custom_excepthook(exc_type, exc_value, exc_traceback):
|
def custom_excepthook(exc_type, exc_value, exc_traceback):
|
||||||
"""全局异常钩子,捕获所有未处理的异常"""
|
"""全局异常钩子,捕获所有未处理的异常"""
|
||||||
if exc_type.__name__ in ['OSError', 'IOError'] and 'Bad file descriptor' in str(exc_value):
|
error_str = str(exc_value)
|
||||||
# 处理 Bad file descriptor 错误,不导致服务器宕机
|
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):
|
if not is_duplicate_error(exc_value):
|
||||||
print(f"[Global Error Handler] {exc_type.__name__}: {exc_value}")
|
print(f"[Global Error Handler] {exc_type.__name__}: {exc_value}")
|
||||||
print("[Traceback]")
|
print("[Traceback]")
|
||||||
|
|||||||
Reference in New Issue
Block a user