aboutsummaryrefslogtreecommitdiff
path: root/crosperf/crosperf.py
diff options
context:
space:
mode:
authorLuis Lozano <llozano@chromium.org>2015-09-30 11:36:27 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-01 15:16:04 -0700
commit45b53c5fee4c044cebd74dbbbd6119fbd51554e7 (patch)
treec98938747c167dbfb15a8265e5897e6290669e95 /crosperf/crosperf.py
parent60a68a5680235ac1a101fb35561901a58298e8ef (diff)
downloadtoolchain-utils-45b53c5fee4c044cebd74dbbbd6119fbd51554e7.tar.gz
Fixed some issues with signal handling and cleanup.
Fixed several issues related to signal handling and cleanup: - Got rid of the extra process wrapper around crosperf. We now do an "exec" to get rid of this extra process. This facilitated signal handling. - Found a better fix for the problem we had with ignoring ctrl-c. Instead of creating a pipe for child process stdin, we now create the child with setsid which has the side effect of creating the child without a terminal associated to it (see man setsid). - By creating the child with setsid, we also allow for easier killing of the child and its descendants since it allows us to use killpg (see man killpg). - Handle SIGTERM by "converting" it into an exit call. This will make sure the atexit routines are called and, furthermore, we can terminate child process when you catch the "SystemExit" exception. - With these changes, crosperf will send a SIGTERM to any cros_sdk, test_that processes that it has started. Before, we would have left over test_that processes that could interfere with a new test_that invocation. BUG=chromium:492826 BUG=chromium:470658 TEST=verified by hand signals are working. Ran toolchain suite. Change-Id: Ibd09ff428a7b402ea2296ecf9b9a34aa5756c93f Reviewed-on: https://chrome-internal-review.googlesource.com/232616 Commit-Ready: Luis Lozano <llozano@chromium.org> Tested-by: Luis Lozano <llozano@chromium.org> Reviewed-by: Yunlian Jiang <yunlian@google.com>
Diffstat (limited to 'crosperf/crosperf.py')
-rwxr-xr-xcrosperf/crosperf.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/crosperf/crosperf.py b/crosperf/crosperf.py
index fc0098d2..e107ea48 100755
--- a/crosperf/crosperf.py
+++ b/crosperf/crosperf.py
@@ -7,6 +7,7 @@
import atexit
import optparse
import os
+import signal
import sys
from experiment_runner import ExperimentRunner
from experiment_runner import MockExperimentRunner
@@ -58,6 +59,16 @@ def Cleanup(experiment):
experiment.Cleanup()
+def CallExitHandler(signum, _):
+ """Signal handler that transforms a signal into a call to exit.
+
+ This is useful because functionality registered by "atexit" will
+ be called. It also means you can "catch" the signal by catching
+ the SystemExit exception.
+ """
+ sys.exit(128 + signum)
+
+
def Main(argv):
parser = optparse.OptionParser(usage=Help().GetUsage(),
description=Help().GetHelp(),
@@ -104,6 +115,7 @@ def Main(argv):
json_report = experiment_file.GetGlobalSettings().GetField("json_report")
+ signal.signal(signal.SIGTERM, CallExitHandler)
atexit.register(Cleanup, experiment)
if options.dry_run: