diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-15 14:11:54 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-15 14:11:54 -0400 |
commit | d401641268aca4d93fd63abebe480fc8fee8ec24 (patch) | |
tree | 5d54805613f3474a3511d0240861f52338d6fe6e /src/lib/Bcfg2 | |
parent | 7754f95f93aa0aa9dc31b017a793b27d172b645f (diff) | |
download | bcfg2-d401641268aca4d93fd63abebe480fc8fee8ec24.tar.gz bcfg2-d401641268aca4d93fd63abebe480fc8fee8ec24.tar.bz2 bcfg2-d401641268aca4d93fd63abebe480fc8fee8ec24.zip |
Executor: better timeout implementation
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r-- | src/lib/Bcfg2/Utils.py | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/lib/Bcfg2/Utils.py b/src/lib/Bcfg2/Utils.py index 3b1559528..7d7d26d5d 100644 --- a/src/lib/Bcfg2/Utils.py +++ b/src/lib/Bcfg2/Utils.py @@ -165,23 +165,19 @@ class Executor(object): self.logger = logging.getLogger(self.__class__.__name__) self.timeout = timeout - def _timeout_callback(self, proc): - """ Get a callback (suitable for passing to - :class:`threading.Timer`) that kills the given process. + def _timeout(self, proc): + """ A function suitable for passing to + :class:`threading.Timer` that kills the given process. :param proc: The process to kill upon timeout. :type proc: subprocess.Popen - :returns: function """ - def _timeout(): - """ Callback that kills ``proc`` """ - if proc.poll() == None: - try: - proc.kill() - self.logger.warning("Process exceeeded timeout, killing") - except OSError: - pass - - return _timeout + :returns: None """ + if proc.poll() == None: + try: + proc.kill() + self.logger.warning("Process exceeeded timeout, killing") + except OSError: + pass def run(self, command, inputdata=None, shell=False, timeout=None): """ Run a command, given as a list, optionally giving it the @@ -212,9 +208,7 @@ class Executor(object): if timeout is None: timeout = self.timeout if timeout is not None: - timer = threading.Timer(float(timeout), - self._timeout_callback(proc), - [proc]) + timer = threading.Timer(float(timeout), self._timeout, [proc]) timer.start() try: if inputdata: |