aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-06-15 23:23:45 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-06-15 23:23:45 +0000
commitc314d33222777e43e8c00c64e6f36c706fdd779a (patch)
tree9138edbe6bf853c1961f0b8e0eeba459ce7a1e87
parentf145a2b923a27519256b0ca8e4457d5f0cdb5cf0 (diff)
parent4821b38054bd785a835b3de359d1ed59e78fa6c5 (diff)
downloadrepohooks-c314d33222777e43e8c00c64e6f36c706fdd779a.tar.gz
Snap for 10331821 from 4821b38054bd785a835b3de359d1ed59e78fa6c5 to udc-d1-release
Change-Id: Ic510a5280108d338b004a45ebc6bdc35337cbe76
-rw-r--r--rh/utils.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/rh/utils.py b/rh/utils.py
index 157e31b..4f1a063 100644
--- a/rh/utils.py
+++ b/rh/utils.py
@@ -369,18 +369,27 @@ def run(cmd, redirect_stdout=False, redirect_stderr=False, cwd=None, input=None,
old_sigint = signal.getsignal(signal.SIGINT)
handler = functools.partial(_kill_child_process, proc, int_timeout,
kill_timeout, cmd, old_sigint)
- signal.signal(signal.SIGINT, handler)
+ # We have to ignore ValueError in case we're run from a thread.
+ try:
+ signal.signal(signal.SIGINT, handler)
+ except ValueError:
+ old_sigint = None
old_sigterm = signal.getsignal(signal.SIGTERM)
handler = functools.partial(_kill_child_process, proc, int_timeout,
kill_timeout, cmd, old_sigterm)
- signal.signal(signal.SIGTERM, handler)
+ try:
+ signal.signal(signal.SIGTERM, handler)
+ except ValueError:
+ old_sigterm = None
try:
(result.stdout, result.stderr) = proc.communicate(input)
finally:
- signal.signal(signal.SIGINT, old_sigint)
- signal.signal(signal.SIGTERM, old_sigterm)
+ if old_sigint is not None:
+ signal.signal(signal.SIGINT, old_sigint)
+ if old_sigterm is not None:
+ signal.signal(signal.SIGTERM, old_sigterm)
if popen_stdout:
# The linter is confused by how stdout is a file & an int.