Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
2ce01ae4
Commit
2ce01ae4
authored
Dec 20, 2013
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove try/except that can hide programming errors
parent
7dc0cc78
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
60 deletions
+24
-60
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+2
-8
dream/simulation/Failure.py
dream/simulation/Failure.py
+12
-18
dream/simulation/LineGenerationJSON.py
dream/simulation/LineGenerationJSON.py
+9
-30
dream/simulation/Machine.py
dream/simulation/Machine.py
+1
-4
No files found.
dream/simulation/CoreObject.py
View file @
2ce01ae4
...
@@ -101,10 +101,7 @@ class CoreObject(Process):
...
@@ -101,10 +101,7 @@ class CoreObject(Process):
activeEntity
=
activeObjectQueue
[
0
]
activeEntity
=
activeObjectQueue
[
0
]
activeObjectQueue
.
pop
(
0
)
#remove the Entity from the queue
activeObjectQueue
.
pop
(
0
)
#remove the Entity from the queue
self
.
timeLastEntityLeft
=
now
()
self
.
timeLastEntityLeft
=
now
()
try
:
self
.
outputTrace
(
activeEntity
.
name
,
"released "
+
self
.
objName
)
self
.
outputTrace
(
activeEntity
.
name
,
"released "
+
self
.
objName
)
except
TypeError
:
pass
return
activeEntity
return
activeEntity
# ================================== gets an entity from the ====================================
# ================================== gets an entity from the ====================================
...
@@ -133,10 +130,7 @@ class CoreObject(Process):
...
@@ -133,10 +130,7 @@ class CoreObject(Process):
activeEntity
.
schedule
.
append
([
activeObject
,
now
()])
activeEntity
.
schedule
.
append
([
activeObject
,
now
()])
activeEntity
.
currentStation
=
self
activeEntity
.
currentStation
=
self
self
.
timeLastEntityEntered
=
now
()
self
.
timeLastEntityEntered
=
now
()
try
:
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
except
TypeError
:
pass
return
activeEntity
return
activeEntity
# ========================== actions to be taken after the simulation ends ======================
# ========================== actions to be taken after the simulation ends ======================
...
...
dream/simulation/Failure.py
View file @
2ce01ae4
...
@@ -84,14 +84,11 @@ class Failure(ObjectInterruption):
...
@@ -84,14 +84,11 @@ class Failure(ObjectInterruption):
def
run
(
self
):
def
run
(
self
):
while
1
:
while
1
:
yield
hold
,
self
,
self
.
rngTTF
.
generateNumber
()
# wait until a failure happens
yield
hold
,
self
,
self
.
rngTTF
.
generateNumber
()
# wait until a failure happens
try
:
if
(
len
(
self
.
getVictimQueue
())
>
0
):
# when a Machine gets failure
if
(
len
(
self
.
getVictimQueue
())
>
0
):
# when a Machine gets failure
self
.
interrupt
(
self
.
victim
)
# while in process it is interrupted
self
.
interrupt
(
self
.
victim
)
# while in process it is interrupted
self
.
victim
.
Up
=
False
self
.
victim
.
Up
=
False
self
.
victim
.
timeLastFailure
=
now
()
self
.
victim
.
timeLastFailure
=
now
()
self
.
outputTrace
(
"is down"
)
self
.
outputTrace
(
"is down"
)
except
AttributeError
:
print
"AttributeError1"
# update the failure time
# update the failure time
failTime
=
now
()
failTime
=
now
()
if
(
self
.
repairman
!=
"None"
):
#if the failure needs a resource to be fixed, the machine waits until the
if
(
self
.
repairman
!=
"None"
):
#if the failure needs a resource to be fixed, the machine waits until the
...
@@ -104,16 +101,13 @@ class Failure(ObjectInterruption):
...
@@ -104,16 +101,13 @@ class Failure(ObjectInterruption):
yield
hold
,
self
,
self
.
rngTTR
.
generateNumber
()
# wait until the repairing process is over
yield
hold
,
self
,
self
.
rngTTR
.
generateNumber
()
# wait until the repairing process is over
self
.
victim
.
totalFailureTime
+=
now
()
-
failTime
self
.
victim
.
totalFailureTime
+=
now
()
-
failTime
try
:
if
(
len
(
self
.
getVictimQueue
())
>
0
):
if
(
len
(
self
.
getVictimQueue
())
>
0
):
reactivate
(
self
.
victim
)
# since repairing is over, the Machine is reactivated
reactivate
(
self
.
victim
)
# since repairing is over, the Machine is reactivated
self
.
victim
.
Up
=
True
self
.
victim
.
Up
=
True
self
.
outputTrace
(
"is up"
)
self
.
outputTrace
(
"is up"
)
if
(
self
.
repairman
!=
"None"
):
#if a resource was used, it is now released
if
(
self
.
repairman
!=
"None"
):
#if a resource was used, it is now released
yield
release
,
self
,
self
.
repairman
.
getResource
()
yield
release
,
self
,
self
.
repairman
.
getResource
()
self
.
repairman
.
totalWorkingTime
+=
now
()
-
timeOperationStarted
self
.
repairman
.
totalWorkingTime
+=
now
()
-
timeOperationStarted
except
AttributeError
:
print
"AttributeError2"
#outputs message to the trace.xls. Format is (Simulation Time | Machine Name | message)
#outputs message to the trace.xls. Format is (Simulation Time | Machine Name | message)
def
outputTrace
(
self
,
message
):
def
outputTrace
(
self
,
message
):
...
...
dream/simulation/LineGenerationJSON.py
View file @
2ce01ae4
...
@@ -178,10 +178,8 @@ def createObjects():
...
@@ -178,10 +178,8 @@ def createObjects():
name
=
element
.
get
(
'name'
,
'not found'
)
# get the name of the element / default 'not_found'
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'
capacity
=
int
(
element
.
get
(
'capacity'
,
'1'
))
# get the capacity of the el. / defautl '1'
O
=
Operator
(
element_id
,
name
,
capacity
)
# create an operator object
O
=
Operator
(
element_id
,
name
,
capacity
)
# create an operator object
try
:
O
.
coreObjectIds
=
getSuccessorList
(
id
)
# update the list of objects that the operator operates
O
.
coreObjectIds
=
getSuccessorList
(
id
)
# update the list of objects that the operator operates
# calling the getSuccessorList() method on the operator
except
:
# calling the getSuccessorList() method on the operator
pass
G
.
OperatorsList
.
append
(
O
)
# add the repairman to the RepairmanList
G
.
OperatorsList
.
append
(
O
)
# add the repairman to the RepairmanList
elif
resourceClass
==
'Dream.OperatorPool'
:
elif
resourceClass
==
'Dream.OperatorPool'
:
id
=
element
.
get
(
'id'
,
'not found'
)
# get the id of the element / default 'not_found'
id
=
element
.
get
(
'id'
,
'not found'
)
# get the id of the element / default 'not_found'
...
@@ -197,11 +195,8 @@ def createObjects():
...
@@ -197,11 +195,8 @@ def createObjects():
else
:
else
:
OP
=
OperatorPool
(
element_id
,
name
,
capacity
,
operatorsList
)
# create a operatorPool object
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
OP
.
coreObjectIds
=
getSuccessorList
(
id
)
# update the list of objects that the operators of the operatorPool operate
try
:
for
operator
in
operatorsList
.
values
():
for
operator
in
operatorsList
.
values
():
operator
.
coreObjectIds
=
OP
.
coreObjectIds
# update the list of objects that the operators operate
operator
.
coreObjectIds
=
OP
.
coreObjectIds
# update the list of objects that the operators operate
except
:
pass
G
.
OperatorPoolsList
.
append
(
OP
)
# add the repairman to the RepairmanList
G
.
OperatorPoolsList
.
append
(
OP
)
# add the repairman to the RepairmanList
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
# loop through all the elements
# loop through all the elements
...
@@ -634,15 +629,9 @@ def initializeObjects():
...
@@ -634,15 +629,9 @@ def initializeObjects():
# ===========================================================================
# ===========================================================================
def
activateObjects
():
def
activateObjects
():
for
element
in
G
.
ObjList
:
for
element
in
G
.
ObjList
:
try
:
activate
(
element
,
element
.
run
())
activate
(
element
,
element
.
run
())
except
AttributeError
:
pass
for
ev
in
G
.
EventGeneratorList
:
for
ev
in
G
.
EventGeneratorList
:
try
:
activate
(
ev
,
ev
.
run
())
activate
(
ev
,
ev
.
run
())
except
AttributeError
:
pass
# ===========================================================================
# ===========================================================================
# reads the WIP of the stations
# reads the WIP of the stations
...
@@ -659,11 +648,7 @@ def createWIP():
...
@@ -659,11 +648,7 @@ def createWIP():
element
[
'id'
]
=
element_id
element
[
'id'
]
=
element_id
wip
=
element
.
get
(
'wip'
,
[])
wip
=
element
.
get
(
'wip'
,
[])
for
entity
in
wip
:
for
entity
in
wip
:
entityClass
=
None
entityClass
=
entity
.
get
(
'_class'
,
None
)
try
:
entityClass
=
entity
.
get
(
'_class'
,
None
)
except
IndexError
:
continue
if
entityClass
==
'Dream.Job'
:
if
entityClass
==
'Dream.Job'
:
id
=
entity
.
get
(
'id'
,
'not found'
)
id
=
entity
.
get
(
'id'
,
'not found'
)
...
@@ -799,17 +784,11 @@ def main(argv=[], input_data=None):
...
@@ -799,17 +784,11 @@ def main(argv=[], input_data=None):
#output data to JSON for every object in the topology
#output data to JSON for every object in the topology
for
element
in
G
.
ObjList
:
for
element
in
G
.
ObjList
:
try
:
element
.
outputResultsJSON
()
element
.
outputResultsJSON
()
except
AttributeError
:
pass
#output data to JSON for every resource in the topology
#output data to JSON for every resource in the topology
for
model_resource
in
G
.
RepairmanList
:
for
model_resource
in
G
.
RepairmanList
:
try
:
model_resource
.
outputResultsJSON
()
model_resource
.
outputResultsJSON
()
except
AttributeError
:
pass
for
job
in
G
.
JobList
:
for
job
in
G
.
JobList
:
job
.
outputResultsJSON
()
job
.
outputResultsJSON
()
...
...
dream/simulation/Machine.py
View file @
2ce01ae4
...
@@ -280,10 +280,7 @@ class Machine(CoreObject):
...
@@ -280,10 +280,7 @@ class Machine(CoreObject):
# checks if the machine down or it can dispose the object
# checks if the machine down or it can dispose the object
# =======================================================================
# =======================================================================
def
ifCanDisposeOrHaveFailure
(
self
):
def
ifCanDisposeOrHaveFailure
(
self
):
try
:
return
self
.
Up
==
False
or
self
.
getReceiverObject
().
canAccept
(
self
)
or
len
(
self
.
getActiveObjectQueue
())
==
0
return
self
.
Up
==
False
or
self
.
getReceiverObject
().
canAccept
(
self
)
or
len
(
self
.
getActiveObjectQueue
())
==
0
except
AttributeError
:
return
False
# =======================================================================
# =======================================================================
# removes an entity from the Machine
# removes an entity from the Machine
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment