Skip to content

Commit 00feba1

Browse files
committed
backward compatabiliy fixes. Works for python 3.6 now.
1 parent d93846e commit 00feba1

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

flask_shell2http/classes.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,23 @@ def run_command(cmd: List[str], timeout: int, key: str) -> Dict:
3535
A Concurrent.Future object where future.result() is the report
3636
"""
3737
start_time: float = time.time()
38-
status: str = "failed"
38+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,)
3939
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}\".")
5652

5753
except Exception as e:
58-
status = "failed"
54+
proc.kill()
5955
returncode = -1
6056
stdout = None
6157
stderr = str(e)
@@ -67,7 +63,6 @@ def run_command(cmd: List[str], timeout: int, key: str) -> Dict:
6763
key=key,
6864
report=stdout,
6965
error=stderr,
70-
status=status,
7166
returncode=returncode,
7267
start_time=start_time,
7368
end_time=end_time,

0 commit comments

Comments
 (0)