donate_cpu: Fix timeout if multithreaded (#2510)
Highly inspired by https://stackoverflow.com/a/4791612.
This commit is contained in:
parent
131befecce
commit
73ee317866
|
@ -7,6 +7,7 @@ import sys
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
import tarfile
|
import tarfile
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ import shlex
|
||||||
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
|
# 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
|
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
|
||||||
# changes)
|
# changes)
|
||||||
CLIENT_VERSION = "1.2.2"
|
CLIENT_VERSION = "1.2.3"
|
||||||
|
|
||||||
# Timeout for analysis with Cppcheck in seconds
|
# Timeout for analysis with Cppcheck in seconds
|
||||||
CPPCHECK_TIMEOUT = 60 * 60
|
CPPCHECK_TIMEOUT = 60 * 60
|
||||||
|
@ -249,12 +250,12 @@ def has_include(path, includes):
|
||||||
def run_command(cmd):
|
def run_command(cmd):
|
||||||
print(cmd)
|
print(cmd)
|
||||||
startTime = time.time()
|
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:
|
try:
|
||||||
comm = p.communicate(timeout=CPPCHECK_TIMEOUT)
|
comm = p.communicate(timeout=CPPCHECK_TIMEOUT)
|
||||||
return_code = p.returncode
|
return_code = p.returncode
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
p.kill()
|
os.killpg(os.getpgid(p.pid), signal.SIGTERM) # Send the signal to all the process groups
|
||||||
comm = p.communicate()
|
comm = p.communicate()
|
||||||
return_code = RETURN_CODE_TIMEOUT
|
return_code = RETURN_CODE_TIMEOUT
|
||||||
stop_time = time.time()
|
stop_time = time.time()
|
||||||
|
|
Loading…
Reference in New Issue