Skip signal handler registration when not on main thread (#18752)

This commit is contained in:
Xinyu Zhang
2026-02-25 19:30:05 -08:00
committed by GitHub
parent 88ad3b894a
commit 119c91cb8b
+24 -16
View File
@@ -882,25 +882,33 @@ def _set_envs_and_config(server_args: ServerArgs):
"Please reinstall the latest version with `pip install sgl-kernel --force-reinstall`", "Please reinstall the latest version with `pip install sgl-kernel --force-reinstall`",
) )
if server_args.custom_sigquit_handler is None: # Signal handlers can only be registered from the main thread.
# Register the signal handler. if threading.current_thread() is threading.main_thread():
# The child processes will send SIGQUIT to this process when any error happens if server_args.custom_sigquit_handler is None:
# This process then clean up the whole process tree # Register the signal handler.
# Note: This sigquit handler is used in the launch phase, and may be replaced by # The child processes will send SIGQUIT to this process when any error happens
# the running_phase_sigquit_handler in the tokenizer manager after the grpc server is launched. # This process then clean up the whole process tree
def launch_phase_sigquit_handler(signum, frame): # Note: This sigquit handler is used in the launch phase, and may be replaced by
logger.error( # the running_phase_sigquit_handler in the tokenizer manager after the grpc server is launched.
"Received sigquit from a child process. It usually means the child failed." def launch_phase_sigquit_handler(signum, frame):
) logger.error(
kill_process_tree(os.getpid()) "Received sigquit from a child process. It usually means the child failed."
)
kill_process_tree(os.getpid())
signal.signal(signal.SIGQUIT, launch_phase_sigquit_handler) signal.signal(signal.SIGQUIT, launch_phase_sigquit_handler)
else:
# Allow users to register a custom SIGQUIT handler for things like crash dump
logger.error(
f"Using custom SIGQUIT handler: {server_args.custom_sigquit_handler}"
)
signal.signal(signal.SIGQUIT, server_args.custom_sigquit_handler)
else: else:
# Allow users to register a custom SIGQUIT handler for things like crash dump logger.warning(
logger.error( "Signal handler is not added because the engine is not in the "
f"Using custom SIGQUIT handler: {server_args.custom_sigquit_handler}" "main thread. This disables the SIGQUIT handler for cleaning up "
"the process tree when a child process fails."
) )
signal.signal(signal.SIGQUIT, server_args.custom_sigquit_handler)
# Set mp start method # Set mp start method
mp.set_start_method("spawn", force=True) mp.set_start_method("spawn", force=True)