I am trying to execute a script using multiprocessing. But in case of errors the script is not throwing exception and pulling out of the processing. Is it possible to have an exception thrown and come out of the execution. I am not able to figure out how to do this since I am new to python.
Below is the script I have written :
import os
import sys
import string
import multiprocessing as mp
path=sys.argv[1]
path_tpt=path+'/tpt_script'
""" Multiprocessing module to generate intermediate exports"""
total_tpt_file_list = []
for filename in os.listdir(path_tpt):
total_tpt_file_list.append(os.path.join(path_tpt,filename))
total_tpt_file_list = list(filter(lambda x:x.endswith('.tpt'), total_tpt_file_list))
total_tpt_file_list = sorted(total_tpt_file_list)
print(total_tpt_file_list)
def run_sed (file_list):
x=file_list.rsplit("/", 2)
y=x[0]
file_name=x[2]
print(file_name)
path_ctl=str(y)+'/ctl_file'
path_tpt=str(y)+'/tpt_script'
path_log=str(y)+'/log'
print("tbuild -f "+ (file_list) + " -j "+ 'tpt_chk_$$ '+ '> '+ os.path.join(path_log,file_name).split('.')[0]+'.log 2>>'+ os.path.join(path_log,file_name).split('.')[0]+'.log')
status=os.system("tbuild -f "+ (file_list) + " -j "+ 'tpt_chk_$$ '+ '> '+ os.path.join(path_log,file_name).split('.')[0]+'.log 2>>'+ os.path.join(path_log,file_name).split('.')[0]+'.log')
try:
p = mp.Pool(processes=(mp.cpu_count()-1))
total_file_list = p.map(run_sed,total_tpt_file_list)
finally:
p.close()
p.join()
print("done")
Please let me know if anymore information is needed.
Thanks in Advance.