diff options
| author | robot-piglet <[email protected]> | 2024-08-28 10:13:37 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2024-08-28 10:56:21 +0300 |
| commit | 5d69584883acf76288028d9eda6f5154bad71f03 (patch) | |
| tree | b4497ba6497373d6b65846161ff807c653231db7 /yt/python | |
| parent | b6ed4760624656bf72a40cf703fadf564d5a5a37 (diff) | |
Intermediate changes
Diffstat (limited to 'yt/python')
| -rw-r--r-- | yt/python/yt/common.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/yt/python/yt/common.py b/yt/python/yt/common.py index e2c96a80ff5..a3c2969125f 100644 --- a/yt/python/yt/common.py +++ b/yt/python/yt/common.py @@ -834,30 +834,34 @@ def wait(predicate, error_message=None, iter=None, sleep_backoff=None, timeout=N if sleep_backoff is None: sleep_backoff = 0.3 + last_exception = None if ignore_exceptions: def check_predicate(): try: - return predicate() + return predicate(), None # Do not catch BaseException because pytest exceptions are inherited from it # pytest.fail raises exception inherited from BaseException. - except Exception: - return False + except Exception as ex: + return False, ex else: - check_predicate = predicate + def check_predicate(): + return predicate(), None if timeout is None: if iter is None: iter = 100 index = 0 while index < iter: - if check_predicate(): + result, last_exception = check_predicate() + if result: return index += 1 time.sleep(sleep_backoff) else: start_time = datetime.datetime.now() while datetime.datetime.now() - start_time < datetime.timedelta(seconds=timeout): - if check_predicate(): + result, last_exception = check_predicate() + if result: return time.sleep(sleep_backoff) @@ -865,5 +869,9 @@ def wait(predicate, error_message=None, iter=None, sleep_backoff=None, timeout=N error_message = error_message() if error_message is None: error_message = "Wait failed" - error_message += " (timeout = {0})".format(timeout if timeout is not None else iter * sleep_backoff) + + error_message += f" (timeout = {timeout if timeout is not None else iter * sleep_backoff}" + if last_exception is not None: + error_message += f", exception = {last_exception}" + error_message += ")" raise WaitFailed(error_message) |
