Main Page
Namespaces
Classes
Package Documentation
GIT Directory
WorkBook
Offline Guide
Release schedule
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
CalibMuon
DTCalibration
python
Workflow
CrabWatch.py
Go to the documentation of this file.
1
#from CrabTask import CrabTask
2
from
crabWrap
import
crabStatus,convertStatus,getOutput
3
import
os,time
4
from
threading
import
Thread,Lock,Event
5
6
class
CrabWatch
(Thread):
7
#def __init__(self, task):
8
# Thread.__init__(self)
9
# self.task = task
10
def
__init__
(self, project, action = getOutput):
11
Thread.__init__(self)
12
self.
project
= project
13
self.
action
= action
14
self.
threshold
= 100.0
15
16
self.
lock
= Lock()
17
self.
finish
= Event()
18
19
def
setThreshold
(self,threshold):
20
self.
threshold
= float(threshold)
21
22
def
run
(self):
23
exit =
False
24
failed=0
25
while
not
exit:
26
#if checkStatus(self.project,80.0): break
27
try
:
28
status =
crabStatus
(self.
project
)
29
except
CrabException:
30
failed+=1
31
print
"Crab retrieve status failed ("
,failed,
")"
32
if
failed>10:
33
raise
34
else
:
35
statusNew =
convertStatus
(status)
36
print
"Relative percentage finished: %.0f%%"
% statusNew[
'Finished'
]
37
print
"Relative percentage failed : %.0f%%"
% statusNew[
'Failed'
]
38
print
"Relative percentage running : %.0f%%"
% statusNew[
'Running'
]
39
if
statusNew[
'Failed'
] > 50.0:
raise
RuntimeError,
'Too many jobs have failed (%.0f%%).'
% statusNew[
'Failed'
]
40
if
statusNew[
'Finished'
] >= self.
threshold
:
break
41
42
self.lock.acquire()
43
if
self.finish.isSet(): exit =
True
44
self.lock.release()
45
46
if
not
exit: time.sleep(180)
47
48
print
"Finished..."
49
50
if
self.
action
: self.
action
(self.
project
)
51
52
if
__name__ ==
'__main__'
:
53
54
project =
None
55
import
sys
56
for
opt
in
sys.argv:
57
if
opt[:8] ==
'project='
:
58
project = opt[8:]
59
60
if
not
project:
raise
ValueError,
'Need to set project'
61
62
crab =
CrabWatch
(project)
63
crab.start()
CrabWatch.CrabWatch.lock
lock
Definition:
CrabWatch.py:16
CrabWatch.CrabWatch.action
action
Definition:
CrabWatch.py:13
CrabWatch.CrabWatch.project
project
Definition:
CrabWatch.py:12
CrabWatch.CrabWatch.threshold
threshold
Definition:
CrabWatch.py:14
CrabWatch.CrabWatch.setThreshold
def setThreshold
Definition:
CrabWatch.py:19
crabWrap.convertStatus
def convertStatus
Definition:
crabWrap.py:174
CrabWatch.CrabWatch.__init__
def __init__
Definition:
CrabWatch.py:10
crabWrap.crabStatus
def crabStatus
Definition:
crabWrap.py:157
CrabWatch.CrabWatch.finish
finish
Definition:
CrabWatch.py:17
CrabWatch.CrabWatch
Definition:
CrabWatch.py:6
CrabWatch.CrabWatch.run
def run
Definition:
CrabWatch.py:22
Generated for CMSSW Reference Manual by
1.8.5