def ProcParallel(cmd,i,njobs,email=False,inName='logIn.log',outName='logOut.log',errName='logErr.log'):
global firstRun
global procs
if firstRun:
logIn = open(inName, 'w')
logOut = open(outName, 'w')
logErr = open(errName, 'w')
firstRun = False
else:
logIn = open(inName, 'a')
logOut = open(outName, 'a')
logErr = open(errName, 'a')
inl = os.tmpfile()
outl = os.tmpfile()
errl = os.tmpfile()
print '\033[1;33m-> %s\033[0m [%i of %i]' %(cmd,i+1,njobs)
start = datetime.datetime.now()
if email==False:
proc = Popen(cmd,shell=True,stdin=inl,stdout=outl,stderr=errl)
else:
proc = Popen(_Notifier(cmd,i+1,njobs,email),shell=True,stdin=inl,stdout=outl,stderr=errl)
procs.append((start,cmd,proc,inl,outl,errl))
if i==njobs-1:
for j, (start, name, proc, inl, outl, errl) in enumerate(procs):
proc.wait()
end = datetime.datetime.now()
print 'Process %i of %i completed. Time: %s' %(j+1,njobs,end-start)
_Temp2Perm(inl,logIn,name,start,end)
_Temp2Perm(outl,logOut,name,start,end)
if errl.tell() != 0:
print '\033[1;31mErrors have occurred!\033[0m (check %s)' %(logErr.name)
_Temp2Perm(errl,logErr,cmd,start,end)
firstRun = True
procs = []
评论列表
文章目录