diff --git a/beat/backend/python/executor.py b/beat/backend/python/executor.py index ce1f7223243604f3451ed1fcfad413f8ec41ba81..bbd6b9a82636e82755565012dc3e6b89ed35b0aa 100644 --- a/beat/backend/python/executor.py +++ b/beat/backend/python/executor.py @@ -92,7 +92,7 @@ class Executor(object): self.data = simplejson.loads(f.read().decode('utf-8')) self.prefix = os.path.join(directory, 'prefix') - self.runner = None + self._runner = None # Temporary caches, if the user has not set them, for performance database_cache = database_cache if database_cache is not None else {} @@ -134,10 +134,21 @@ class Executor(object): ) + @property + def runner(self): + """Returns the algorithm runner + + This property allows for lazy loading of the runner + """ + + if self._runner is None: + self._runner = self.algorithm.runner() + return self._runner + + def setup(self): """Sets up the algorithm to start processing""" - self.runner = self.algorithm.runner() retval = self.runner.setup(self.data['parameters']) logger.debug("User algorithm is setup") return retval @@ -146,7 +157,6 @@ class Executor(object): def prepare(self): """Prepare the algorithm""" - self.runner = self.algorithm.runner() retval = self.runner.prepare(self.data_loaders) logger.debug("User algorithm is prepared") return retval