diff --git a/spin/cmds/meson.py b/spin/cmds/meson.py index cd9c43d..c2afa01 100644 --- a/spin/cmds/meson.py +++ b/spin/cmds/meson.py @@ -4,6 +4,7 @@ import os import re import shutil +import signal import sys from enum import Enum from pathlib import Path @@ -815,7 +816,27 @@ def run(ctx, *, args, build_dir=None): cmd_args = ["bash", "-c", cmd_args] _set_pythonpath(build_dir, quiet=True) - p = _run(cmd_args, echo=False, shell=shell, sys_exit=False) + + is_windows = sys.platform == "win32" + + if not is_windows: + # Let the subprocess handle its own signals + # Except on Windows, where it already seems to work as intended, + # and `preexec_fn` is not supported + signal.signal(signal.SIGINT, signal.SIG_IGN) + + def attach_sigint(): + # Reset SIGINT handler to default + signal.signal(signal.SIGINT, signal.SIG_DFL) + + # --- launch subprocess --- + p = _run( + cmd_args, + echo=False, + shell=shell, + sys_exit=False, + preexec_fn=None if is_windows else attach_sigint, + ) # Is the user trying to run a Python script, without calling the Python interpreter? executable = args[0]