Commit 34c575bc authored by Jonas Kaufmann's avatar Jonas Kaufmann Committed by Antoine Kaufmann
Browse files

implement Ctrl+C handling for DistributedSimpleRuntime

parent 5923f91a
...@@ -40,6 +40,8 @@ class DistributedSimpleRuntime(Runtime): ...@@ -40,6 +40,8 @@ class DistributedSimpleRuntime(Runtime):
self.verbose = verbose self.verbose = verbose
self.executors = executors self.executors = executors
self._running: asyncio.Task
def add_run(self, run: Run): def add_run(self, run: Run):
if not isinstance(run.experiment, DistributedExperiment): if not isinstance(run.experiment, DistributedExperiment):
raise RuntimeError('Only distributed experiments supported') raise RuntimeError('Only distributed experiments supported')
...@@ -54,10 +56,17 @@ class DistributedSimpleRuntime(Runtime): ...@@ -54,10 +56,17 @@ class DistributedSimpleRuntime(Runtime):
run.env, run.env,
self.verbose self.verbose
) )
for executor in self.executors:
await run.prep_dirs(executor) try:
await runner.prepare() for executor in self.executors:
run.output = await runner.run() await run.prep_dirs(executor)
await runner.prepare()
except asyncio.CancelledError:
# it is safe to just exit here because we are not running any
# simulators yet
return
run.output = await runner.run() # already handles CancelledError
self.complete.append(run) self.complete.append(run)
pathlib.Path(run.outpath).parent.mkdir(parents=True, exist_ok=True) pathlib.Path(run.outpath).parent.mkdir(parents=True, exist_ok=True)
...@@ -66,15 +75,16 @@ class DistributedSimpleRuntime(Runtime): ...@@ -66,15 +75,16 @@ class DistributedSimpleRuntime(Runtime):
async def start(self): async def start(self):
for run in self.runnable: for run in self.runnable:
asyncio.run(self.do_run(run)) if self._interrupted:
return
self._running = asyncio.create_task(self.do_run(run))
await self._running
def interrupt(self): def interrupt(self):
# TODO implement this
super().interrupt() super().interrupt()
print( if self._running:
'Ctrl+C handling for DistributedRuntime not yet implemented. ' self._running.cancel()
'You need to kill the processes manually.'
)
def auto_dist( def auto_dist(
......
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