I am using python 3.5 and subprocess.check_output
with a timeout
option to get the output of a subprocess. This works if I call the executable directly, e.g.
>>> import subproces
>>> subprocess.check_output(["/usr/bin/gedit"],timeout=1)
...
subprocess.TimeoutExpired: Command '/usr/bin/gedit' timed out after 1 seconds
However, if I call
>>> subprocess.check_output(["strace","/usr/bin/gedit"],timeout=1)
, the TimeoutExpired
is raised only after I terminate the gedit process myself. So the function subprocess.check_output
keeps blocking for longer than 1 second.
How would I use the subprocess.check_output
function (or similar) to get it to raise the exception correctly?