From 73ee31786617d56f0581d1d0977f84073bbd1ea9 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Tue, 25 Feb 2020 11:49:56 +0100 Subject: [PATCH] donate_cpu: Fix timeout if multithreaded (#2510) Highly inspired by https://stackoverflow.com/a/4791612. --- tools/donate_cpu_lib.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 49bc1952a..5d9810db2 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -7,6 +7,7 @@ import sys import socket import time import re +import signal import tarfile import shlex @@ -14,7 +15,7 @@ import shlex # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # changes) -CLIENT_VERSION = "1.2.2" +CLIENT_VERSION = "1.2.3" # Timeout for analysis with Cppcheck in seconds CPPCHECK_TIMEOUT = 60 * 60 @@ -249,12 +250,12 @@ def has_include(path, includes): def run_command(cmd): print(cmd) startTime = time.time() - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid) try: comm = p.communicate(timeout=CPPCHECK_TIMEOUT) return_code = p.returncode except subprocess.TimeoutExpired: - p.kill() + os.killpg(os.getpgid(p.pid), signal.SIGTERM) # Send the signal to all the process groups comm = p.communicate() return_code = RETURN_CODE_TIMEOUT stop_time = time.time()