When using Python bindings to a C++ library that spawn processes, the SIGINT might not be received by all child processes. Instead, Python only processes SIGINT once execution returns to its scope.
To prevent this behavior, you may want to try process groups - setpgrp - set the process group ID.
For example:
Group all spawned processes together
Handle signals in Python
Forward the signal captured to the entire process group
Code example:
import os
import signal
import sys
from types import FrameType
from typing import NoReturn
# Set the current process in its own process group
os.setpgrp()
def signal_handler(signalnum: int, _: FrameType) -> NoReturn:
# Ignore the captured signal number while handling it to prevent maximum recursion depth
signal.signal(signalnum=signalnum, handler=signal.SIG_IGN)
print(f"Received signal {signalnum}")
# Send signal to all processes in the group
os.killpg(0, signalnum)
# Exit the execution
sys.exit(1)
# Configure the signals you want to capture
# Capture SIGINT (Ctrl+C) and call `signal_handler` custom function
signal.signal(signalnum=signal.SIGINT, handler=signal_handler)
# Your code
...
I hope this helps!
system, which ignores SIGINT — but we can only guess without a fuller problem description.