def run(self): logger.info('EXECUTE THREAD HIEARCHY') slaves = self.create_slave_threads() # for each tier logger.meta('-'*80) for i, tier in enumerate(self.thread_hierarchy): i += 1 try: # make all specified threadslaves execute their function logger.info('start executing tier no ' + str(i)) for slave in slaves: if slave.tag in tier: (run_id, f) = tier.get(slave.tag) slave.execute((run_id, f)) #wait for all threads to finish for slave in slaves: if slave.thread and slave.thread.isAlive(): slave.thread.join() # test if any slaves have caused an exception, then rethrow it if slave.exception: raise slave.exception[1], None, slave.exception[2] if slave.thread and slave.thread.returncode != 0 and ctx.fail_fast: raise Fast_Fail_Exeception("remote execution exited with code %d!" % slave.thread.returncode) except Fast_Fail_Exeception, e: logger.error(e.message) logger.error('broke execution: an explanation ought to have been printed above me') break; finally:
def inner(srv, run_id, accum): try: logger.info("executing " + run_id) result = f(srv, run_id, accum) # accumulate the output for the next execution if result: # expects the result to specify a result and a namespace. (namespace, result) = result logger.debug("namespace: " + namespace) logger.debug("content: " + str(result)) if isinstance(result, dict): if not namespace in accum: logger.debug("new namespace added to accum: " + namespace) accum[namespace] = {} self.accum[namespace].update(result) else: self.accum[namespace] = result except: self.exception = sys.exc_info()
if slave.tag in tier: (run_id, f) = tier.get(slave.tag) slave.execute((run_id, f)) #wait for all threads to finish for slave in slaves: if slave.thread and slave.thread.isAlive(): slave.thread.join() # test if any slaves have caused an exception, then rethrow it if slave.exception: raise slave.exception[1], None, slave.exception[2] if slave.thread and slave.thread.returncode != 0 and ctx.fail_fast: raise Fast_Fail_Exeception("remote execution exited with code %d!" % slave.thread.returncode) except Fast_Fail_Exeception, e: logger.error(e.message) logger.error('broke execution: an explanation ought to have been printed above me') break; finally: logger.meta('-'*80) #TODO: is everything shutdown properly? logger.info('Shutdown slaves') for slave in slaves: slave.close() logger.meta('-'*80) logger.info('THREAD HIEARCHY FINISHED') logger.meta('-'*80) logger.meta('')