Skip to content
Snippets Groups Projects
Commit 96d57e3c authored by Christopher Spinrath's avatar Christopher Spinrath
Browse files

Make timeouts configurable

parent f722be81
No related branches found
No related tags found
No related merge requests found
...@@ -60,11 +60,12 @@ class Variable: ...@@ -60,11 +60,12 @@ class Variable:
class Task: class Task:
def __init__(self, name, work_dir, base_command, parameters): def __init__(self, name, work_dir, base_command, parameters, timeout):
self._name = name self._name = name
self._work_dir = work_dir self._work_dir = work_dir
self._base_command = base_command self._base_command = base_command
self._parameters = parameters self._parameters = parameters
self._timeout = timeout
@property @property
def name(self): def name(self):
...@@ -74,8 +75,12 @@ class Task: ...@@ -74,8 +75,12 @@ class Task:
def work_dir(self): def work_dir(self):
return self._work_dir return self._work_dir
def run(self, variables): def run(self, variables, global_timeout, dry_run):
args = [self._base_command] if dry_run:
args = ["echo"]
else:
args = []
args.append(self._base_command)
for p in self._parameters: for p in self._parameters:
if not isinstance(p, dict): if not isinstance(p, dict):
...@@ -102,13 +107,18 @@ class Task: ...@@ -102,13 +107,18 @@ class Task:
# print(f"pushd {self._work_dir}") # print(f"pushd {self._work_dir}")
# print(" ".join(args)) # print(" ".join(args))
# print("popd") # print("popd")
timeout = self._timeout
if timeout is not None and global_timeout is not None:
timeout = min(timeout, global_timeout)
elif global_timeout is not None:
timeout = global_timeout
try: try:
subprocess.run( subprocess.run(
" ".join(args), " ".join(args),
shell = True, shell = True,
cwd = self._work_dir, cwd = self._work_dir,
timeout = 3600, # FIXME timeout = timeout,
) )
return False return False
...@@ -128,6 +138,8 @@ class Task: ...@@ -128,6 +138,8 @@ class Task:
parameters = data.get("parameters", []) parameters = data.get("parameters", [])
timeout = data.get("timeout", None)
if "work-dir" in data: if "work-dir" in data:
work_dir = pathlib.Path(data["work-dir"]).expanduser() work_dir = pathlib.Path(data["work-dir"]).expanduser()
else: else:
...@@ -135,7 +147,7 @@ class Task: ...@@ -135,7 +147,7 @@ class Task:
assert work_dir.exists(), f"Working directory \"{work_dir}\" for task \"{name}\" does not exist!" assert work_dir.exists(), f"Working directory \"{work_dir}\" for task \"{name}\" does not exist!"
return cls(name, work_dir, base_command, parameters) return cls(name, work_dir, base_command, parameters, timeout)
class Config: class Config:
...@@ -177,7 +189,9 @@ class Config: ...@@ -177,7 +189,9 @@ class Config:
@click.command() @click.command()
@click.argument("config_file", type = click.Path( @click.argument("config_file", type = click.Path(
exists = True, file_okay = True, dir_okay = False, readable = True, path_type = pathlib.Path)) exists = True, file_okay = True, dir_okay = False, readable = True, path_type = pathlib.Path))
def main(config_file): @click.option("--global-timeout", type = click.IntRange(1), default = 7200)
@click.option("--dry-run", is_flag = True)
def main(config_file, global_timeout, dry_run):
c = Config.from_file(config_file) c = Config.from_file(config_file)
print(f"> Running experiment \"{c.name}\"") print(f"> Running experiment \"{c.name}\"")
...@@ -202,7 +216,7 @@ def main(config_file): ...@@ -202,7 +216,7 @@ def main(config_file):
for task in c.tasks: for task in c.tasks:
print(f"Running task {task.name}") print(f"Running task {task.name}")
timed_out = task.run(variables) timed_out = task.run(variables, global_timeout, dry_run)
print() print()
if timed_out: # repetitions are useless if tasks time out if timed_out: # repetitions are useless if tasks time out
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment