Quick terminate on fail added

This commit is contained in:
Ganesh Gore 2019-09-13 23:56:38 -06:00
parent 10eba0f78c
commit e5c99c8b12
1 changed files with 12 additions and 14 deletions

View File

@ -252,7 +252,7 @@ def generate_each_task_actions(taskname):
flow_run_cmd_list.append({ flow_run_cmd_list.append({
"arch": arch, "arch": arch,
"bench": bench, "bench": bench,
"name": "%02d_arch%s_%s" % (indx, bench["top_module"], lbl), "name": "%02d_%s_%s" % (indx, bench["top_module"], lbl),
"run_dir": flow_run_dir, "run_dir": flow_run_dir,
"commands": command, "commands": command,
"finished" : False, "finished" : False,
@ -345,14 +345,11 @@ def strip_child_logger_info(line):
def run_single_script(s, eachJob, job_list): def run_single_script(s, eachJob, job_list):
logger.debug('Added job in pool')
with s: with s:
logger.debug("Running OpenFPGA flow with " + thread_name = threading.currentThread().getName()
" ".join(eachJob["commands"]))
name = threading.currentThread().getName()
eachJob["starttime"] = time.time() eachJob["starttime"] = time.time()
try: try:
logfile = "%s_out.log" % name logfile = "%s_out.log" % thread_name
with open(logfile, 'w+') as output: with open(logfile, 'w+') as output:
output.write("* "*20 + '\n') output.write("* "*20 + '\n')
output.write("RunDirectory : %s\n" % os.getcwd()) output.write("RunDirectory : %s\n" % os.getcwd())
@ -360,6 +357,7 @@ def run_single_script(s, eachJob, job_list):
eachJob["commands"] eachJob["commands"]
output.write(" ".join(command) + '\n') output.write(" ".join(command) + '\n')
output.write("* "*20 + '\n') output.write("* "*20 + '\n')
logger.debug("Running OpenFPGA flow with [%s]" % command)
process = subprocess.Popen(command, process = subprocess.Popen(command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -371,19 +369,19 @@ def run_single_script(s, eachJob, job_list):
output.write(line) output.write(line)
process.wait() process.wait()
if process.returncode: if process.returncode:
raise subprocess.CalledProcessError(0, command) raise subprocess.CalledProcessError(0, " ".join(command))
eachJob["status"] = True eachJob["status"] = True
except: except:
logger.exception("Failed to execute openfpga flow - " + logger.exception("Failed to execute openfpga flow - " +
eachJob["name"]) eachJob["name"])
if not args.continue_on_fail: if not args.continue_on_fail:
clean_up_and_exit("Faile to run task %s exiting" % name) os._exit(1)
eachJob["endtime"] = time.time() eachJob["endtime"] = time.time()
timediff = timedelta(seconds=(eachJob["endtime"]-eachJob["starttime"])) timediff = timedelta(seconds=(eachJob["endtime"]-eachJob["starttime"]))
timestr = humanize.naturaldelta(timediff) if "humanize" in sys.modules \ timestr = humanize.naturaldelta(timediff) if "humanize" in sys.modules \
else str(timediff) else str(timediff)
logger.info("%s Finished with returncode %d, Time Taken %s " % logger.info("%s Finished with returncode %d, Time Taken %s " %
(name, process.returncode, timestr)) (thread_name, process.returncode, timestr))
eachJob["finished"] = True eachJob["finished"] = True
no_of_finished_job = sum([ not eachJ["finished"] for eachJ in job_list]) no_of_finished_job = sum([ not eachJ["finished"] for eachJ in job_list])
logger.info("***** %d runs pending *****" % (no_of_finished_job)) logger.info("***** %d runs pending *****" % (no_of_finished_job))
@ -391,13 +389,13 @@ def run_single_script(s, eachJob, job_list):
def run_actions(job_list): def run_actions(job_list):
thread_sema = threading.Semaphore(args.maxthreads) thread_sema = threading.Semaphore(args.maxthreads)
thred_list = [] thread_list = []
for _ , eachjob in enumerate(job_list): for _ , eachjob in enumerate(job_list):
t = threading.Thread(target=run_single_script, t = threading.Thread(target=run_single_script, name=eachjob["name"],
name=eachjob["name"], args=(thread_sema, eachjob, job_list)) args=(thread_sema, eachjob, job_list))
t.start() t.start()
thred_list.append(t) thread_list.append(t)
for eachthread in thred_list: for eachthread in thread_list:
eachthread.join() eachthread.join()