Commit a718942b authored by tonyg@chromium.org's avatar tonyg@chromium.org

[Telemetry] Terminate any dangling subprocesses

This is designed to prevent deadlocks on the buildbots.

I couldn't figure out a way to kill them without killing the parent as well. I
also haven't looked into a Windows equivalent yet.

BUG=357059

Review URL: https://codereview.chromium.org/301313007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274036 0039d316-1c4b-4281-b951-d872f2087c98
parent 411f87ce
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
"""Hooks that apply globally to all scripts that import or use Telemetry.""" """Hooks that apply globally to all scripts that import or use Telemetry."""
import atexit
import os import os
import signal import signal
import sys import sys
from telemetry.core import platform
from telemetry.core import util from telemetry.core import util
from telemetry.util import exception_formatter from telemetry.util import exception_formatter
...@@ -18,6 +20,7 @@ def InstallHooks(): ...@@ -18,6 +20,7 @@ def InstallHooks():
InstallUnhandledExceptionFormatter() InstallUnhandledExceptionFormatter()
InstallStackDumpOnSigusr1() InstallStackDumpOnSigusr1()
InstallTerminationHook() InstallTerminationHook()
InstallAtExitHook()
def RemoveAllStalePycFiles(base_dir): def RemoveAllStalePycFiles(base_dir):
...@@ -71,3 +74,24 @@ def InstallTerminationHook(): ...@@ -71,3 +74,24 @@ def InstallTerminationHook():
exception_formatter.PrintFormattedFrame(stack_frame, exception_string) exception_formatter.PrintFormattedFrame(stack_frame, exception_string)
sys.exit(-1) sys.exit(-1)
signal.signal(signal.SIGTERM, PrintStackAndExit) 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment