stub_template_host redirect SIGINT and SIGTERM to subprocess
Test: manual Change-Id: I561f581f7413dc18b2d449f4ef338db3b6b9ca47
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -43,7 +44,18 @@ def Main():
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
# close_fds=False so that you can run binaries with files provided on the command line:
|
# close_fds=False so that you can run binaries with files provided on the command line:
|
||||||
# my_python_app --file <(echo foo)
|
# 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:
|
finally:
|
||||||
shutil.rmtree(runfiles_path, ignore_errors=True)
|
shutil.rmtree(runfiles_path, ignore_errors=True)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user