diff options
| author | 2023-03-22 14:17:26 +0000 | |
|---|---|---|
| committer | 2023-03-22 14:17:26 +0000 | |
| commit | 6116a44ec3f1941df54774569b384d6acd1b5baa (patch) | |
| tree | c1e7ef6a6b13937c6ee08a88c65248e39d9b651f /python/scripts | |
| parent | 9d8e0158de866564def4414ffa34b9d1dfa4a6cb (diff) | |
| parent | 2a3a42683c06f43a6166fd29ce67cc4621ad1347 (diff) | |
Merge "stub_template_host redirect SIGINT and SIGTERM to subprocess"
Diffstat (limited to 'python/scripts')
| -rw-r--r-- | python/scripts/stub_template_host.txt | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt index 5eedc180c..2d1bd4a9b 100644 --- a/python/scripts/stub_template_host.txt +++ b/python/scripts/stub_template_host.txt @@ -3,6 +3,7 @@ import os import tempfile import shutil +import signal import sys import subprocess import zipfile @@ -43,7 +44,18 @@ def Main(): sys.stdout.flush() # close_fds=False so that you can run binaries with files provided on the command line: # my_python_app --file <(echo foo) - sys.exit(subprocess.call(args, close_fds=False)) + p = subprocess.Popen(args, close_fds=False) + + def handler(sig, frame): + p.send_signal(sig) + + # Redirect SIGINT and SIGTERM to subprocess + signal.signal(signal.SIGINT, handler) + signal.signal(signal.SIGTERM, handler) + + p.wait() + + sys.exit(p.returncode) finally: shutil.rmtree(runfiles_path, ignore_errors=True) |