def run(self): try: if not os.path.exists(self.outputFile): Configs.log("Running a task, output file: {}".format( self.outputFile)) mod = importlib.import_module( Task.functionModuleMap[self.taskType]) func = getattr(mod, self.taskType) func(**self.taskArgs) Configs.log("Completed a task, output file: {}".format( self.outputFile)) else: Configs.log("File already exists: {}".format(self.outputFile)) except Exception as exc: Configs.error("Task for {} threw an exception:\n{}".format( self.outputFile, exc)) Configs.error(traceback.format_exc()) raise finally: self.isFinished = True
def main(): ''' Resolve the args/configs, spin up the task manager (which deals with worker threads and handles parallelism), and get started on the main alignment task. ''' startTime = time.time() args = parseArgs() buildConfigs(args) Configs.log("MAGUS was run with: {}".format(" ".join(sys.argv))) try: manager.startTaskManager() mainAlignmentTask() except: Configs.error("MAGUS aborted with an exception..") Configs.error(traceback.format_exc()) finally: manager.stopTaskManager() endTime = time.time() Configs.log("MAGUS finished in {} seconds..".format(endTime - startTime))
def runCommand(**kwargs): command = kwargs["command"] Configs.log("Running an external tool, command: {}".format(command)) runner = subprocess.run(command, shell = True, cwd = kwargs["workingDir"], universal_newlines = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) try: runner.check_returncode() except: Configs.error("Command encountered error: {}".format(command)) Configs.error("Exit code: {}".format(runner.returncode)) Configs.error("Output: {}".format(runner.stdout)) raise for srcPath, destPath in kwargs.get("fileCopyMap", {}).items(): shutil.move(srcPath, destPath)
def checkTaskManager(): if not TaskManager.managerFuture.running(): Configs.error("Task manager is dead for some reason..") TaskManager.managerFuture.result() raise Exception("Task manager is dead for some reason..")