Files
wehub-resource-sync e9a2f726c9
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:29:51 +08:00

28 lines
741 B
Python

# SPDX-License-Identifier: Apache-2.0
"""Fatal process-exit helpers."""
from __future__ import annotations
import faulthandler
import logging
import os
from typing import NoReturn
logger = logging.getLogger(__name__)
FATAL_EXIT_CODE = 70
FATAL_TEARDOWN_TIMEOUT_S = 60.0
def fatal_exit(reason: str, exit_code: int = FATAL_EXIT_CODE) -> NoReturn:
"""Terminate immediately so an external supervisor can restart cleanly."""
logger.critical(
"%s; exiting process so the supervisor can restart with a clean state",
reason,
)
try:
faulthandler.dump_traceback(all_threads=True)
except Exception:
logger.exception("Failed to dump thread tracebacks before fatal exit")
os._exit(exit_code)