Skip to content

Commit

Permalink
Make warnings on accessing results of failed jobs less chatty SO107 S…
Browse files Browse the repository at this point in the history
…CMSUITE-8725
  • Loading branch information
dormrod committed Dec 6, 2024
1 parent bf61d75 commit f205bde
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions core/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import threading
from os.path import join as opj
from subprocess import PIPE
from typing import List, Dict
from typing import List, Dict, Optional

from scm.plams.core.errors import FileError, ResultsError
from scm.plams.core.functions import config, log
Expand Down Expand Up @@ -50,6 +50,19 @@ def _privileged_access():
return False


# def _is_called_from_job_method(method: List[str], prev_method: Optional[str]):
# """Analyze contents of the current stack to find out if current function was called by a given method from the same |Job| instance.
# """
# from scm.plams.core.basejob import Job
#
# for frame in inspect.getouterframes(inspect.currentframe()):
# cal, arg = _caller_name_and_arg(frame[0])
# prev_cal, prev_arg = _caller_name_and_arg(frame[0].f_back)
# if cal in method and (prev_calprev_cal == "_finalize" and arg == prev_arg and isinstance(arg, Job):
# return True
# return False


def _restrict(func):
"""Decorator that wraps methods of |Results| instances.
Expand Down Expand Up @@ -80,10 +93,21 @@ def guardian(self, *args, **kwargs):
raise ResultsError("Using Results associated with deleted job")

elif self.job.status in [JobStatus.CRASHED, JobStatus.FAILED]:
if func.__name__ == "wait": # waiting for crashed of failed job should not trigger any warnings/exceptions
# waiting for crashed of failed job should not trigger any warnings/exceptions
# and neither should checking the status from this job with 'ok', 'check' or 'get_errormsg'
suppress_errors = func.__name__ == "wait"
if not suppress_errors:
for frame in inspect.getouterframes(inspect.currentframe()):
cal, arg = _caller_name_and_arg(frame[0])
if arg == self.job and cal in ["ok", "check", "get_errormsg"]:
suppress_errors = True
break

if suppress_errors:
cal, arg = _caller_name_and_arg(inspect.currentframe())
if isinstance(arg, Results):
return func(self, *args, **kwargs)

if config.ignore_failure:
log("WARNING: Trying to obtain results of crashed or failed job {}".format(self.job.name), 3)
try:
Expand Down

0 comments on commit f205bde

Please sign in to comment.