The feature I would like to request is being able to set a timeout like this:
with exec_helpers.Subprocess() as executor:
try:
executor.check_call("/tmp/test.sh", shell=False, timeout=2)
except exec_helpers.ExecHelperTimeoutError as e:
print(e)
except exec_helpers.CalledProcessError as e:
print(e)
If test.sh contains: sleep 5; echo 123 it would be nice if the process throws the timeout error after 2 seconds, currently it's done after 5 seconds.
To compare with "raw" subprocess:
try:
# this works, throws after 2 seconds
subprocess.check_output("/tmp/test.sh", stderr=subprocess.STDOUT, timeout=2, shell=False)
except subprocess.TimeoutExpired as e:
print(e)
except subprocess.CalledProcessError as e:
print(e)
try:
# this also doesn't work, throws after 5 seconds, because of the shell=True
subprocess.check_output("/tmp/test.sh", stderr=subprocess.STDOUT, timeout=2, shell=True)
except subprocess.TimeoutExpired as e:
print(e)
except subprocess.CalledProcessError as e:
print(e)