Skip to content

Commit

Permalink
Remove custom Windows interrupt handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Nov 17, 2024
1 parent 5b60ef2 commit 5c0a79d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies = [
"click",
"tomli; python_version < '3.11'",
"colorama; platform_system == 'Windows'",
"pywin32; platform_system == 'Windows'",
"importlib_metadata >= 7"
]
dynamic = ['version']
Expand Down
26 changes: 4 additions & 22 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import shutil
import signal
import subprocess
import sys
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -819,43 +818,26 @@ def run(ctx, *, args, build_dir=None):
_set_pythonpath(build_dir, quiet=True)

is_windows = sys.platform == "win32"
is_posix = not is_windows

if is_posix:
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)

kwargs = (
{"creationflags": subprocess.CREATE_NEW_PROCESS_GROUP} if is_windows else {}
)

# --- launch subprocess ---
p = _run(
cmd_args,
echo=False,
shell=shell,
sys_exit=False,
preexec_fn=attach_sigint if is_posix else None,
**kwargs,
preexec_fn=None if is_windows else attach_sigint,
)

# Handle Ctrl+C (SIGINT) on Windows
def windows_ctrl_handler(ctrl_type):
if ctrl_type == signal.CTRL_C_EVENT:
# Forward CTRL_BREAK_EVENT to the child process
p.send_signal(signal.CTRL_BREAK_EVENT)
return True
return False

if is_windows:
import win32api

win32api.SetConsoleCtrlHandler(windows_ctrl_handler, True)

# Is the user trying to run a Python script, without calling the Python interpreter?
executable = args[0]
if (
Expand Down

0 comments on commit 5c0a79d

Please sign in to comment.