From 30ba6c77522ae2f6129b5b8113651dde8c1be851 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jul 10 2020 10:36:43 +0000 Subject: Remove execute_cmd timeout feature - it is not used anywhere and not python2 compatible. --- diff --git a/cccc/utils.py b/cccc/utils.py index d6e5cb3..fe751c1 100644 --- a/cccc/utils.py +++ b/cccc/utils.py @@ -5,14 +5,13 @@ import subprocess import sys -def execute_cmd(args, stdout=None, stderr=None, cwd=None, timeout=None, env=None, +def execute_cmd(args, stdout=None, stderr=None, cwd=None, env=None, ignore_fail=False): """ Executes command defined by `args`. If `stdout` or `stderr` is set to Python file object, the stderr/stdout output is redirecter to that file. If `cwd` is set, current working directory is set accordingly for the executed command. - If `timeout` is set, kill process after that number of seconds. If `env` is set, use that instead of current environment variables. :param args: List defining the command to execute. @@ -21,7 +20,6 @@ def execute_cmd(args, stdout=None, stderr=None, cwd=None, timeout=None, env=None :param stderr: Python file object to redirect the stderr to. :type stderr: file :param cwd: String defining the current working directory for command. - :param timeout: Timeout in seconds after which the process is killed. :param env: If not None, a mapping that defines environment variables for running the command, used instead the current environment. :type env: dict @@ -34,13 +32,7 @@ def execute_cmd(args, stdout=None, stderr=None, cwd=None, timeout=None, env=None proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env) - try: - out, err = proc.communicate(timeout=timeout) - except subprocess.TimeoutExpired: - proc.kill() - proc.communicate() - err_msg = "Command '%s' has taken more time than allowed (%d seconds)" % (args, timeout) - raise RuntimeError(err_msg) + out, err = proc.communicate() if not ignore_fail and proc.returncode != 0: sys.stdout.write(out.decode("utf-8")) diff --git a/tests/test_utils.py b/tests/test_utils.py index fbfc8e1..6434145 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,6 @@ import os import sys import tempfile -import time from .helpers import LocalWebServer from cccc.utils import download_file, execute_cmd @@ -36,15 +35,6 @@ class TestUtilsExecuteCmd(unittest.TestCase): execute_cmd(["/usr/bin/true"], ignore_fail=True) execute_cmd(["/usr/bin/false"], ignore_fail=True) - def test_execute_cmd_timeout_called(self): - start_time = time.time() - with self.assertRaisesRegex( - RuntimeError, "Command .* has taken more time .*"): - execute_cmd(["/usr/bin/sleep", "5"], timeout=1) - stop_time = time.time() - - self.assertTrue(stop_time - start_time < 2) - @patch("sys.stdout", new=StringIO()) def test_execute_cmd_with_env(self): execute_cmd(["/usr/bin/printenv", "mY_RanDoM_EnV_varblE"], stdout=sys.stdout,