Another way is to make the subprocess ignore SIGINT.
import subprocess import signal subprocess.Popen(["sleep", "100"], preexec_fn=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
Using preexec_fn ensures that the parent process's SIGINT handler is not changed. (if it's changed you need to restore it like this.)
Of course, this will only work if the subprocess does not proceed to reinstate the signal handler. In the following case where the subprocess installs a signal handler, the subprocess would still be killed:
import subprocess import signal process=subprocess.Popen(["python", "-c", "import signal\nimport time\nsignal.signal(signal.SIGINT, signal.SIG_DFL)\nwhile True: \n print(1)\n time.sleep(1)"], preexec_fn=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN)) process.wait()
Credit to https://stackoverflow.com/a/3731948/5267751 .