Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
15cead28
Commit
15cead28
authored
Jul 07, 2023
by
Jonas Kaufmann
Committed by
Antoine Kaufmann
Nov 05, 2023
Browse files
orchestration: prevent cancellation while terminating simulators and collecting output
parent
05bfbefb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
33 deletions
+44
-33
experiments/simbricks/orchestration/runners.py
experiments/simbricks/orchestration/runners.py
+44
-33
No files found.
experiments/simbricks/orchestration/runners.py
View file @
15cead28
...
@@ -150,10 +150,41 @@ class ExperimentBaseRunner(ABC):
...
@@ -150,10 +150,41 @@ class ExperimentBaseRunner(ABC):
for
sc
in
self
.
wait_sims
:
for
sc
in
self
.
wait_sims
:
await
sc
.
wait
()
await
sc
.
wait
()
async
def
terminate_collect_sims
(
self
)
->
ExpOutput
:
"""Terminates all simulators and collects output."""
self
.
out
.
set_end
()
if
self
.
verbose
:
print
(
f
'
{
self
.
exp
.
name
}
: cleaning up'
)
await
self
.
before_cleanup
()
# "interrupt, terminate, kill" all processes
scs
=
[]
for
_
,
sc
in
self
.
running
:
scs
.
append
(
asyncio
.
create_task
(
sc
.
int_term_kill
()))
await
asyncio
.
shield
(
asyncio
.
wait
(
scs
))
# wait for all processes to terminate
for
_
,
sc
in
self
.
running
:
await
asyncio
.
shield
(
sc
.
wait
())
# remove all sockets
scs
=
[]
for
(
executor
,
sock
)
in
self
.
sockets
:
scs
.
append
(
asyncio
.
create_task
(
executor
.
rmtree
(
sock
)))
if
scs
:
await
asyncio
.
shield
(
asyncio
.
wait
(
scs
))
# add all simulator components to the output
for
sim
,
sc
in
self
.
running
:
self
.
out
.
add_sim
(
sim
,
sc
)
await
asyncio
.
shield
(
self
.
after_cleanup
())
return
self
.
out
async
def
run
(
self
)
->
ExpOutput
:
async
def
run
(
self
)
->
ExpOutput
:
try
:
try
:
self
.
out
.
set_start
()
self
.
out
.
set_start
()
graph
=
self
.
sim_graph
()
graph
=
self
.
sim_graph
()
ts
=
graphlib
.
TopologicalSorter
(
graph
)
ts
=
graphlib
.
TopologicalSorter
(
graph
)
ts
.
prepare
()
ts
.
prepare
()
...
@@ -181,38 +212,18 @@ class ExperimentBaseRunner(ABC):
...
@@ -181,38 +212,18 @@ class ExperimentBaseRunner(ABC):
self
.
out
.
set_failed
()
self
.
out
.
set_failed
()
traceback
.
print_exc
()
traceback
.
print_exc
()
finally
:
# The bare except above guarantees that we always execute the following
self
.
out
.
set_end
()
# code, which terminates all simulators and produces a proper output
# file.
# shut things back down
terminate_collect_task
=
asyncio
.
create_task
(
if
self
.
verbose
:
self
.
terminate_collect_sims
()
print
(
f
'
{
self
.
exp
.
name
}
: cleaning up'
)
)
# prevent terminate_collect_task from being cancelled
await
self
.
before_cleanup
()
while
True
:
try
:
# "interrupt, terminate, kill" all processes
return
await
asyncio
.
shield
(
terminate_collect_task
)
scs
=
[]
except
asyncio
.
CancelledError
:
for
_
,
sc
in
self
.
running
:
pass
scs
.
append
(
asyncio
.
create_task
(
sc
.
int_term_kill
()))
await
asyncio
.
wait
(
scs
)
# wait for all processes to terminate
for
_
,
sc
in
self
.
running
:
await
sc
.
wait
()
# remove all sockets
scs
=
[]
for
(
executor
,
sock
)
in
self
.
sockets
:
scs
.
append
(
asyncio
.
create_task
(
executor
.
rmtree
(
sock
)))
if
scs
:
await
asyncio
.
wait
(
scs
)
# add all simulator components to the output
for
sim
,
sc
in
self
.
running
:
self
.
out
.
add_sim
(
sim
,
sc
)
await
self
.
after_cleanup
()
return
self
.
out
class
ExperimentSimpleRunner
(
ExperimentBaseRunner
):
class
ExperimentSimpleRunner
(
ExperimentBaseRunner
):
...
...
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