Skip to content

Commit

Permalink
[Pipelines] Work around BuildBuddy CLI signal bug (#55279)
Browse files Browse the repository at this point in the history
Due to a BuildBuddy CLI bug
(buildbuddy-io/buildbuddy#8326), when using
`./bazelw run`, we get invoked with the `SIGINT` handler being
`SIG_IGN`. This is annoying because it becomes much harder to terminate
the process when `SIGINT` is disabled. While less-commonly used,
BuildBuddy also disables `SIGTERM` and `SIGQUIT`. Detect this situation
and return the state to what it would have been if we had been invoked
without the BuildBuddy CLI.

Part of AITLIB-132.

MODULAR_ORIG_COMMIT_REV_ID: bf1a3105755564fa03eaad2cf7c6e2636418e7a0
  • Loading branch information
akirchhoff-modular authored and modularbot committed Feb 13, 2025
1 parent 63630d9 commit 290463b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pipelines/python/max/entrypoints/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import functools
import logging
import os
import signal

import click
from max.pipelines import PIPELINE_REGISTRY, PipelineConfig
Expand Down Expand Up @@ -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()

0 comments on commit 290463b

Please sign in to comment.