test
CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatrixRunner.py
Go to the documentation of this file.
1 
2 import os, sys, time
3 import random
4 
5 from Configuration.PyReleaseValidation.WorkFlow import WorkFlow
6 from Configuration.PyReleaseValidation.WorkFlowRunner import WorkFlowRunner
7 
8 # ================================================================================
9 
10 class MatrixRunner(object):
11 
12  def __init__(self, wfIn=None, nThrMax=4, nThreads=1):
13 
14  self.workFlows = wfIn
15 
16  self.threadList = []
17  self.maxThreads = nThrMax
18  self.nThreads = nThreads
19 
20  #the directories in which it happened
21  self.runDirs={}
22 
23  def activeThreads(self):
24 
25  nActive = 0
26  for t in self.threadList:
27  if t.isAlive() : nActive += 1
28 
29  return nActive
30 
31 
32  def runTests(self, opt):
33 
34  testList=opt.testList
35  dryRun=opt.dryRun
36  cafVeto=opt.cafVeto
37 
38  startDir = os.getcwd()
39 
40  report=''
41  noRun=(self.maxThreads==0)
42  if noRun:
43  print 'Not running the wf, only creating cfgs and logs'
44  print 'resetting to default number of threads'
45  self.maxThreads=4
46 
47  print 'Running in %s thread(s)' % self.maxThreads
48 
49 
50  for wf in self.workFlows:
51 
52  if testList and float(wf.numId) not in [float(x) for x in testList]: continue
53 
54  item = wf.nameId
55  if os.path.islink(item) : continue # ignore symlinks
56 
57  # make sure we don't run more than the allowed number of threads:
58  while self.activeThreads() >= self.maxThreads:
59  time.sleep(10)
60  continue
61 
62  print '\nPreparing to run %s %s' % (wf.numId, item)
63  sys.stdout.flush()
64  current = WorkFlowRunner(wf,noRun,dryRun,cafVeto, opt.dasOptions, opt.jobReports, opt.nThreads)
65  self.threadList.append(current)
66  current.start()
67  if not dryRun:
68  time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
69 
70  # wait until all threads are finished
71  while self.activeThreads() > 0:
72  time.sleep(0.5)
73 
74 
75  #wrap up !
76  totpassed=[]
77  totfailed=[]
78  def count(collect,result):
79  #pad with zeros
80  for i in range(len(collect),len(result)):
81  collect.append(0)
82  for i,c in enumerate(result):
83  collect[i]+=c
84 
85  for pingle in self.threadList:
86  pingle.join()
87  try:
88  count(totpassed,pingle.npass)
89  count(totfailed,pingle.nfail)
90  report+=pingle.report
91  self.runDirs[pingle.wf.numId]=pingle.wfDir
92  except Exception as e:
93  msg = "ERROR retrieving info from thread: " + str(e)
94  report += msg
95 
96  report+=' '.join(map(str,totpassed))+' tests passed, '+' '.join(map(str,totfailed))+' failed\n'
97  print report
98  sys.stdout.flush()
99 
100  runall_report_name='runall-report-step123-.log'
101  runall_report=open(runall_report_name,'w')
102  runall_report.write(report)
103  runall_report.close()
104  os.chdir(startDir)
105 
106  anyFail=sum(totfailed)
107 
108  return anyFail
109 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18