diff options
author | Raphaël Beamonte <raphael.beamonte@gmail.com> | 2012-12-23 21:36:36 -0500 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2013-01-04 14:20:47 +0100 |
commit | daecdace119ecee546ece48450760b404f8a6189 (patch) | |
tree | c1b792b7c6802e7dbcae3c3b5bcb647584f3f9cf /rteval/modules | |
parent | 20f0a8ec4f2ae9d2235b1976d21006a270ccb0d9 (diff) | |
download | rteval-daecdace119ecee546ece48450760b404f8a6189.tar.gz rteval-daecdace119ecee546ece48450760b404f8a6189.tar.xz rteval-daecdace119ecee546ece48450760b404f8a6189.zip |
Corrects RuntimeError behavior using a new rtevalRuntimeError for modules
Previously, when a module was raising a RuntimeError, parent threads weren't
using it to stop the execution of the program. As RuntimeError are frequently
fatal for what we want to set for the execution of rteval, this patches proposes
to use a new rtevalRuntimeError which will set a flag on a module when raised to
allow its parent to raise a RuntimeError to the main thread.
Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'rteval/modules')
-rw-r--r-- | rteval/modules/__init__.py | 35 | ||||
-rw-r--r-- | rteval/modules/loads/kcompile.py | 9 |
2 files changed, 35 insertions, 9 deletions
diff --git a/rteval/modules/__init__.py b/rteval/modules/__init__.py index bbd2b6c..0191767 100644 --- a/rteval/modules/__init__.py +++ b/rteval/modules/__init__.py @@ -26,7 +26,14 @@ from rteval.Log import Log from rteval.rtevalConfig import rtevalCfgSection import time, libxml2, threading, optparse -__all__ = ["rtevalModulePrototype", "ModuleContainer", "RtEvalModules"] +__all__ = ["rtevalRuntimeError", "rtevalModulePrototype", "ModuleContainer", "RtEvalModules"] + +class rtevalRuntimeError(RuntimeError): + def __init__(self, mod, message): + RuntimeError.__init__(self, message) + + # The module had a RuntimeError, we set the flag + mod._setRuntimeError() class rtevalModulePrototype(threading.Thread): @@ -42,6 +49,7 @@ class rtevalModulePrototype(threading.Thread): self._name = name self.__logger = logger self.__ready = False + self.__runtimeError = False self.__events = {"start": threading.Event(), "stop": threading.Event(), "finished": threading.Event()} @@ -63,6 +71,16 @@ class rtevalModulePrototype(threading.Thread): self.__ready = state + def hadRuntimeError(self): + "Returns a boolean if the module had a RuntimeError" + return self.__runtimeError + + + def _setRuntimeError(self, state=True): + "Sets the runtimeError flag for the module" + self.__runtimeError = state + + def setStart(self): "Sets the start event state" self.__events["start"].set() @@ -381,7 +399,7 @@ and will also be given to the instantiated objects during module import.""" start their workloads yet""" if self.__modules.ModulesLoaded() == 0: - raise RuntimeError("No %s modules configured" % self._module_type) + raise rtevalRuntimeError("No %s modules configured" % self._module_type) self._logger.log(Log.INFO, "Starting %s modules" % self._module_type) for (modname, mod) in self.__modules: @@ -394,8 +412,11 @@ start their workloads yet""" busy = False for (modname, mod) in self.__modules: if not mod.isReady(): - busy = True - self._logger.log(Log.DEBUG, "Waiting for %s" % modname) + if not mod.hadRuntimeError(): + busy = True + self._logger.log(Log.DEBUG, "Waiting for %s" % modname) + else: + raise RuntimeError("Runtime error starting the %s %s module" % (modname, self._module_type)) if busy: time.sleep(1) @@ -403,6 +424,11 @@ start their workloads yet""" self._logger.log(Log.DEBUG, "All %s modules are ready" % self._module_type) + def hadError(self): + "Returns True if one or more modules had a RuntimeError" + return self.__runtimeError + + def Unleash(self): """Unleashes all the loaded modules workloads""" @@ -426,7 +452,6 @@ start their workloads yet""" return True - def Stop(self): """Stops all the running workloads from in all the loaded modules""" diff --git a/rteval/modules/loads/kcompile.py b/rteval/modules/loads/kcompile.py index a38e12f..2aa3eb5 100644 --- a/rteval/modules/loads/kcompile.py +++ b/rteval/modules/loads/kcompile.py @@ -24,6 +24,7 @@ # import sys, os, glob, subprocess from signal import SIGTERM +from rteval.modules import rtevalRuntimeError from rteval.modules.loads import CommandLineLoad from rteval.Log import Log @@ -39,14 +40,14 @@ class Kcompile(CommandLineLoad): if self._cfg.has_key('tarball'): tarfile = os.path.join(self.srcdir, self._cfg.tarfile) if not os.path.exists(tarfile): - raise RuntimeError, " tarfile %s does not exist!" % tarfile + raise rtevalRuntimeError(self, " tarfile %s does not exist!" % tarfile) self.source = tarfile else: tarfiles = glob.glob(os.path.join(self.srcdir, "%s*" % kernel_prefix)) if len(tarfiles): self.source = tarfiles[0] else: - raise RuntimeError, " no kernel tarballs found in %s" % self.srcdir + raise rtevalRuntimeError(self, " no kernel tarballs found in %s" % self.srcdir) # check for existing directory kdir=None @@ -76,7 +77,7 @@ class Kcompile(CommandLineLoad): kdir=d break if kdir == None: - raise RuntimeError, "Can't find kernel directory!" + raise rtevalRuntimeError(self, "Can't find kernel directory!") self.jobs = 1 # We only run one instance of the kcompile job self.mydir = os.path.join(self.builddir, kdir) self._log(Log.DEBUG, "mydir = %s" % self.mydir) @@ -96,7 +97,7 @@ class Kcompile(CommandLineLoad): ret = subprocess.call(["make", "-C", self.mydir, "mrproper", "allmodconfig"], stdin=null, stdout=out, stderr=err) if ret: - raise RuntimeError, "kcompile setup failed: %d" % ret + raise rtevalRuntimeError(self, "kcompile setup failed: %d" % ret) except KeyboardInterrupt, m: self._log(Log.DEBUG, "keyboard interrupt, aborting") return |