Skip to content

Commit

Permalink
Flush stdout in retry functions (BugFix) (#1590)
Browse files Browse the repository at this point in the history
* Flush stdout in retry functions

* Use flush parameter

* Flush on last print
  • Loading branch information
pedro-avalos authored Nov 8, 2024
1 parent 498c548 commit bdf6739
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions checkbox-support/checkbox_support/helpers/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ def run_with_retry(f, max_attempts, delay, *args, **kwargs):
print()
print("=" * len(attempt_string))
print(attempt_string)
print("=" * len(attempt_string))
print("=" * len(attempt_string), flush=True)
try:
result = f(*args, **kwargs)
return result
except BaseException as e:
print("Attempt {} failed:".format(attempt))
print(e)
print()
print(flush=True)
if attempt >= max_attempts:
print("All the attempts have failed!")
print("All the attempts have failed!", flush=True)
raise
min_delay = min(
initial_delay * (backoff_factor**attempt),
Expand All @@ -73,7 +73,10 @@ def run_with_retry(f, max_attempts, delay, *args, **kwargs):
) # Jitter: up to 50% of the delay
total_delay = min_delay + jitter
print(
"Waiting {:.2f} seconds before retrying...".format(total_delay)
"Waiting {:.2f} seconds before retrying...".format(
total_delay
),
flush=True,
)
time.sleep(total_delay)

Expand Down

0 comments on commit bdf6739

Please sign in to comment.