diff --git a/pipelines/python/max/entrypoints/pipelines.py b/pipelines/python/max/entrypoints/pipelines.py index b8b2543c..09956422 100644 --- a/pipelines/python/max/entrypoints/pipelines.py +++ b/pipelines/python/max/entrypoints/pipelines.py @@ -7,6 +7,7 @@ import functools import logging import os +import signal import click from max.pipelines import PIPELINE_REGISTRY, PipelineConfig @@ -213,4 +214,18 @@ def cli_list(): if directory := os.getenv("BUILD_WORKSPACE_DIRECTORY"): os.chdir(directory) + # Workaround for https://github.com/buildbuddy-io/buildbuddy/issues/8326 + if ( + signal.getsignal(signal.SIGINT) == signal.SIG_IGN + and signal.getsignal(signal.SIGTERM) == signal.SIG_IGN + and signal.getsignal(signal.SIGQUIT) == signal.SIG_IGN + ): + # For SIGINT, Python remaps SIG_DFL to default_int_handler on startup. + # We do the same here to retain the same behavior we would get if we + # started normally. (SIG_DFL terminates the process immediately; + # default_int_handler raises KeyboardInterrupt.) + signal.signal(signal.SIGINT, signal.default_int_handler) + signal.signal(signal.SIGTERM, signal.SIG_DFL) + signal.signal(signal.SIGQUIT, signal.SIG_DFL) + main()