Skip to content

Commit

Permalink
Simplify the exception
Browse files Browse the repository at this point in the history
  • Loading branch information
PGijsbers committed Dec 22, 2024
1 parent 0660453 commit 6bb1085
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
17 changes: 3 additions & 14 deletions amlb/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ def file_lock(path, timeout=-1):


class StaleProcessError(subprocess.TimeoutExpired):
def __init__(self, cmd, timeout, output=None, stderr=None, setting=None):
super().__init__(cmd, timeout, output, stderr)
self.setting = setting

def __str__(self):
return (
f"Process '{self.cmd}' was aborted after producing no output for {self.timeout} seconds. "
f"If the process is expected to take more time, please raise the '{self.setting}' limit."
)
pass


def run_subprocess(
Expand Down Expand Up @@ -119,14 +111,11 @@ def communicate(process, input=None, timeout=None):

retcode = process.poll()
if retcode is None:
# Process still lives: communication stopped because of activity timeout
# Process still lives => communication stopped because of activity timeout
process.kill()
process.wait()
raise StaleProcessError(
process.args,
float("nan"),
output=stdout,
stderr=stderr,
process.args, float("nan"), output=stdout, stderr=stderr
)

if check and retcode:
Expand Down
16 changes: 11 additions & 5 deletions runbenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
str_sanitize,
zip_path,
StaleProcessError,
Namespace,
)
from amlb import log, AutoMLError
from amlb.defaults import default_dirs
Expand Down Expand Up @@ -362,11 +363,16 @@
try:
bench.setup(amlb.SetupMode[args.setup])
except StaleProcessError as e:
e.timeout = amlb_res.config.setup.activity_timeout
e.setting = "setup.activity_timeout"
raise
if args.setup != "only":
res = bench.run(args.task, args.fold)
setting = "setup.activity_timeout"
timeout = Namespace.get(amlb_res.config, setting)
log.error(
f"Process '{e.cmd}' was aborted after producing no output for {timeout} seconds. "
f"If the process is expected to take more time, please raise the '{setting}' limit."
)
exit_code = 1
else:
if args.setup != "only":
res = bench.run(args.task, args.fold)
except (ValueError, AutoMLError) as e:
log.error("\nERROR:\n%s", e)
if extras.get("verbose") is True:
Expand Down

0 comments on commit 6bb1085

Please sign in to comment.