Skip to content

Commit

Permalink
Add warning log for failed tries.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 630604504
  • Loading branch information
dustinvtran authored and edward-bot committed May 4, 2024
1 parent 8f69eb2 commit 717b71d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions edward2/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def robust_map(
max_workers: int | None = ...,
raise_error: Literal[False] = ...,
retry_exception_types: list[type[Exception]] | None = ...,
) -> Sequence[U | V]:
) -> list[U | V]:
...


Expand All @@ -52,7 +52,7 @@ def robust_map(
max_workers: int | None = ...,
raise_error: Literal[True] = ...,
retry_exception_types: list[type[Exception]] | None = ...,
) -> Sequence[U]:
) -> list[U]:
...


Expand All @@ -66,7 +66,7 @@ def robust_map(
max_workers: int | None = None,
raise_error: bool = False,
retry_exception_types: list[type[Exception]] | None = None,
) -> Sequence[U | V]:
) -> list[U | V]:
"""Maps a function to inputs using a threadpool.
The map supports exception handling, retries with exponential backoff, and
Expand Down Expand Up @@ -107,12 +107,18 @@ def robust_map(
fn_with_backoff = tenacity.retry(
retry=retry,
wait=tenacity.wait_random_exponential(min=1, max=30),
before_sleep=tenacity.before_sleep_log(
logging.get_absl_logger(), logging.WARNING
),
)(fn)
else:
fn_with_backoff = tenacity.retry(
retry=retry,
wait=tenacity.wait_random_exponential(min=1, max=30),
stop=tenacity.stop_after_attempt(max_retries + 1),
before_sleep=tenacity.before_sleep_log(
logging.get_absl_logger(), logging.WARNING
),
)(fn)
if index_to_output is None:
index_to_output = {}
Expand Down

0 comments on commit 717b71d

Please sign in to comment.