Skip to content

Commit

Permalink
Let subprocess launched by run handle its own sigint (#246)
Browse files Browse the repository at this point in the history
Otherwise, the subprocess is aborted by the parent process. This change
makes `spin run python -i ...` usable.

Tested on Windows, but on that platform no changes seem to be necessary.

Closes #235
  • Loading branch information
stefanv authored Nov 17, 2024
1 parent 5e91741 commit 06dbe73
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
import shutil
import signal
import sys
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 06dbe73

Please sign in to comment.