Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Unified Diff: tools/telemetry/telemetry/util/global_hooks.py

Issue 301313007: [Telemetry] Terminate any dangling subprocesses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/util/global_hooks.py
diff --git a/tools/telemetry/telemetry/util/global_hooks.py b/tools/telemetry/telemetry/util/global_hooks.py
index c7d559922cfdf5d4c9be15f97fc45c4937fa06b6..4d50417268507a3bd0043e7039ab9d38b4f5faa6 100644
--- a/tools/telemetry/telemetry/util/global_hooks.py
+++ b/tools/telemetry/telemetry/util/global_hooks.py
@@ -4,10 +4,12 @@
"""Hooks that apply globally to all scripts that import or use Telemetry."""
+import atexit
import os
import signal
import sys
+from telemetry.core import platform
from telemetry.core import util
from telemetry.util import exception_formatter
@@ -18,6 +20,7 @@ def InstallHooks():
InstallUnhandledExceptionFormatter()
InstallStackDumpOnSigusr1()
InstallTerminationHook()
+ InstallAtExitHook()
def RemoveAllStalePycFiles(base_dir):
@@ -71,3 +74,24 @@ def InstallTerminationHook():
exception_formatter.PrintFormattedFrame(stack_frame, exception_string)
sys.exit(-1)
signal.signal(signal.SIGTERM, PrintStackAndExit)
+
+
+def InstallAtExitHook():
+ """Ensure all subprocesses are killed.
+
+ Subprocesses should never outlive Telemetry. If they do, they can cause
+ hangs on the builbots.
+ """
+ # TODO(tonyg): Find a way to do something similar on Windows.
+ if platform.GetHostPlatform().GetOSName() == 'win':
+ return
+
+ # Create new process group and become its leader.
+ os.setpgrp()
+
+ # At exit, terminate everything in the group.
+ def KillGroup():
+ # Ignore the TERM we're about to get.
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
+ os.killpg(0, signal.SIGTERM)
+ atexit.register(KillGroup)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698