Commit ab9b5bd1 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

experiments: use executor in prep_dirs for mkdir/rmtree

preparation for remote execution, some directories need to be cleaned
up/created on the remote host some locally
parent 254fae55
......@@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import simbricks.exectools as exectools
import shutil
import pathlib
......@@ -35,13 +36,18 @@ class Run(object):
def name(self):
return self.experiment.name + '.' + str(self.index)
def prep_dirs(self):
async def prep_dirs(self, exec=exectools.LocalExecutor()):
shutil.rmtree(self.env.workdir, ignore_errors=True)
await exec.rmtree(self.env.workdir)
if self.env.create_cp:
shutil.rmtree(self.env.cpdir, ignore_errors=True)
await exec.rmtree(self.env.cpdir)
pathlib.Path(self.env.workdir).mkdir(parents=True, exist_ok=True)
await exec.mkdir(self.env.workdir)
pathlib.Path(self.env.cpdir).mkdir(parents=True, exist_ok=True)
await exec.mkdir(self.env.cpdir)
class Runtime(object):
def add_run(self, run):
......
......@@ -36,7 +36,7 @@ class LocalSimpleRuntime(Runtime):
self.runnable.append(run)
async def do_run(self, run):
run.prep_dirs()
await run.prep_dirs()
await run.experiment.prepare(run.env, verbose=self.verbose)
run.output = await run.experiment.run(run.env, verbose=self.verbose)
self.complete.append(run)
......@@ -73,8 +73,8 @@ class LocalParallelRuntime(Runtime):
async def do_run(self, run):
''' actually starts a run '''
run.prep_dirs()
await run.prep_dirs()
await run.experiment.prepare(run.env, verbose=self.verbose)
print('starting run ', run.name())
run.output = await run.experiment.run(run.env, verbose=self.verbose)
......
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