Commit 2d1caec3 authored by Jonathan Michalon's avatar Jonathan Michalon

Handle non-existing commands

Handle OSError exceptions (such as non-existing command) for the
Popen command spawning.
Surround that by a mutex as Popen is not atomic when failing!
parent de0f5ad0
from lib.subprocess_compat import TimeoutExpired, Popen, PIPE
from threading import Lock
# used for hack in Check.exec_with_timeout() because Popen is not
# atomic when failing to spawn command
# see
lock = Lock()
class Host(object):
......@@ -41,7 +48,14 @@ class Check(object):
def exec_with_timeout(self, command, timeout=2):
self.errmsg = ''
p = Popen(command, stdout=PIPE, stderr=PIPE)
p = Popen(command, stdout=PIPE, stderr=PIPE)
except OSError as e:
self.errmsg = 'Check not available: ' + e.strerror
return False
out, err = p.communicate(timeout=timeout)
except TimeoutExpired:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment