@@ -35,27 +35,23 @@ def run_command(cmd: List[str], timeout: int, key: str) -> Dict:
35
35
A Concurrent.Future object where future.result() is the report
36
36
"""
37
37
start_time : float = time .time ()
38
- status : str = "failed"
38
+ proc = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ,)
39
39
try :
40
- p = subprocess .run (
41
- cmd ,
42
- stdout = subprocess .PIPE ,
43
- stderr = subprocess .PIPE ,
44
- text = "ascii" ,
45
- timeout = timeout ,
46
- )
47
- stdout , stderr , returncode = p .stdout , p .stderr , p .returncode
48
- if returncode == 0 :
49
- status = "success"
50
- elif stderr and stdout :
51
- status = "reported_with_fails"
52
- elif stdout and not stderr :
53
- status = "success"
54
-
55
- logger .info (f"Job: '{ key } ' --> finished with status: '{ status } '." )
40
+ outs , errs = proc .communicate (timeout = int (timeout ))
41
+ stdout = outs .decode ("ascii" )
42
+ stderr = errs .decode ("ascii" )
43
+ returncode = proc .returncode
44
+ logger .info (f"Job: '{ key } ' --> finished with returncode: '{ returncode } '." )
45
+
46
+ except subprocess .TimeoutExpired :
47
+ proc .kill ()
48
+ stdout , _ = [s .decode ("ascii" ) for s in proc .communicate ()]
49
+ stderr = f"command timedout after { timeout } seconds."
50
+ returncode = proc .returncode
51
+ logger .error (f"Job: '{ key } ' --> failed. Reason: \" { stderr } \" ." )
56
52
57
53
except Exception as e :
58
- status = "failed"
54
+ proc . kill ()
59
55
returncode = - 1
60
56
stdout = None
61
57
stderr = str (e )
@@ -67,7 +63,6 @@ def run_command(cmd: List[str], timeout: int, key: str) -> Dict:
67
63
key = key ,
68
64
report = stdout ,
69
65
error = stderr ,
70
- status = status ,
71
66
returncode = returncode ,
72
67
start_time = start_time ,
73
68
end_time = end_time ,
0 commit comments