Commit fc39f716 authored by Jérome Perrin's avatar Jérome Perrin

Remove try/except that can hide programming errors

parent bcbc200b
......@@ -127,10 +127,7 @@ class CoreObject(Process):
self.downTimeInTryingToReleaseCurrentEntity=0
self.timeLastEntityLeft=now()
try:
self.outputTrace(activeEntity.name, "released "+self.objName)
except TypeError:
pass
self.outputTrace(activeEntity.name, "released "+self.objName)
return activeEntity
# =======================================================================
......@@ -175,10 +172,7 @@ class CoreObject(Process):
self.nameLastEntityEntered=activeEntity.name # this holds the name of the last entity that got into Machine
self.downTimeProcessingCurrentEntity=0
try:
self.outputTrace(activeEntity.name, "got into "+self.objName)
except TypeError:
pass
self.outputTrace(activeEntity.name, "got into "+self.objName)
return activeEntity
# =======================================================================
......@@ -359,4 +353,4 @@ class CoreObject(Process):
# (failure, break, preemption, etc)
# =======================================================================
def interruptionActions(self):
pass
\ No newline at end of file
pass
......@@ -83,14 +83,11 @@ class Failure(ObjectInterruption):
def run(self):
while 1:
yield hold,self,self.rngTTF.generateNumber() # wait until a failure happens
try:
if(len(self.getVictimQueue())>0): # when a Machine gets failure
self.interruptVictim() # while in process it is interrupted
self.victim.Up=False
self.victim.timeLastFailure=now()
self.outputTrace("is down")
except AttributeError:
print "AttributeError1"
if(len(self.getVictimQueue())>0): # when a Machine gets failure
self.interruptVictim() # while in process it is interrupted
self.victim.Up=False
self.victim.timeLastFailure=now()
self.outputTrace("is down")
# update the failure time
failTime=now()
if(self.repairman!="None"): #if the failure needs a resource to be fixed, the machine waits until the
......@@ -103,13 +100,10 @@ class Failure(ObjectInterruption):
yield hold,self,self.rngTTR.generateNumber() # wait until the repairing process is over
self.victim.totalFailureTime+=now()-failTime
try:
if(len(self.getVictimQueue())>0):
self.reactivateVictim() # since repairing is over, the Machine is reactivated
self.victim.Up=True
self.outputTrace("is up")
if(self.repairman!="None"): #if a resource was used, it is now released
yield release,self,self.repairman.getResource()
self.repairman.totalWorkingTime+=now()-timeOperationStarted
except AttributeError:
print "AttributeError2"
if(len(self.getVictimQueue())>0):
self.reactivateVictim() # since repairing is over, the Machine is reactivated
self.victim.Up=True
self.outputTrace("is up")
if(self.repairman!="None"): #if a resource was used, it is now released
yield release,self,self.repairman.getResource()
self.repairman.totalWorkingTime+=now()-timeOperationStarted
......@@ -193,10 +193,8 @@ def createObjects():
name = element.get('name', 'not found') # get the name of the element / default 'not_found'
capacity = int(element.get('capacity', '1')) # get the capacity of the el. / defautl '1'
O = Operator(element_id, name, capacity) # create an operator object
try:
O.coreObjectIds=getSuccessorList(id) # update the list of objects that the operator operates
except: # calling the getSuccessorList() method on the operator
pass
O.coreObjectIds=getSuccessorList(id) # update the list of objects that the operator operates
# calling the getSuccessorList() method on the operator
G.OperatorsList.append(O) # add the repairman to the RepairmanList
elif resourceClass=='Dream.OperatorPool':
id = element.get('id', 'not found') # get the id of the element / default 'not_found'
......@@ -212,11 +210,8 @@ def createObjects():
else:
OP = OperatorPool(element_id, name, capacity,operatorsList) # create a operatorPool object
OP.coreObjectIds=getSuccessorList(id) # update the list of objects that the operators of the operatorPool operate
try:
for operator in operatorsList.values():
operator.coreObjectIds=OP.coreObjectIds # update the list of objects that the operators operate
except:
pass
for operator in operatorsList.values():
operator.coreObjectIds=OP.coreObjectIds # update the list of objects that the operators operate
G.OperatorPoolsList.append(OP) # add the repairman to the RepairmanList
# -----------------------------------------------------------------------
# loop through all the elements
......@@ -807,20 +802,11 @@ def initializeObjects():
# ===========================================================================
def activateObjects():
for element in G.ObjList:
try:
activate(element, element.run())
except AttributeError:
pass
activate(element, element.run())
for ev in G.EventGeneratorList:
try:
activate(ev, ev.run())
except AttributeError:
pass
activate(ev, ev.run())
for oi in G.ObjectInterruptionList:
try:
activate(oi, oi.run())
except AttributeError:
pass
activate(oi, oi.run())
# ===========================================================================
# reads the WIP of the stations
......@@ -840,11 +826,7 @@ def createWIP():
element['id'] = element_id
wip=element.get('wip', [])
for entity in wip:
entityClass=None
try:
entityClass=entity.get('_class', None)
except IndexError:
continue
entityClass=entity.get('_class', None)
if entityClass=='Dream.OrderComponent':
id=entity.get('id', 'not found')
......@@ -896,7 +878,7 @@ def createWIP():
G.JobList.append(OC)
G.WipList.append(OC)
G.EntityList.append(OC)
elif entityClass=='Dream.Job':
id=entity.get('id', 'not found')
name=entity.get('name', 'not found')
......@@ -1143,17 +1125,11 @@ def main(argv=[], input_data=None):
#output data to JSON for every object in the topology
for element in G.ObjList:
try:
element.outputResultsJSON()
except AttributeError:
pass
element.outputResultsJSON()
#output data to JSON for every resource in the topology
for model_resource in G.RepairmanList:
try:
model_resource.outputResultsJSON()
except AttributeError:
pass
model_resource.outputResultsJSON()
for job in G.JobList:
job.outputResultsJSON()
......
......@@ -264,10 +264,7 @@ class Machine(CoreObject):
# checks if the machine down or it can dispose the object
# =======================================================================
def ifCanDisposeOrHaveFailure(self):
try:
return self.Up==False or self.getReceiverObject().canAccept(self) or len(self.getActiveObjectQueue())==0
except AttributeError:
return False
return self.Up==False or self.getReceiverObject().canAccept(self) or len(self.getActiveObjectQueue())==0
# =======================================================================
# removes an entity from the Machine
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment