From 60d071789dd0c22daeb011015d6597f080f31cf1 Mon Sep 17 00:00:00 2001 From: "panxuchen.pxc" Date: Tue, 8 Oct 2024 14:36:40 +0800 Subject: [PATCH] fix retry --- src/agentscope/rpc/retry_strategy.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/agentscope/rpc/retry_strategy.py b/src/agentscope/rpc/retry_strategy.py index b62ec0342..230b57917 100644 --- a/src/agentscope/rpc/retry_strategy.py +++ b/src/agentscope/rpc/retry_strategy.py @@ -138,12 +138,14 @@ def retry( # pylint: disable=R1710 except Exception as e: if attempt == self.max_retries: raise TimeoutError("Max timeout exceeded.") from e - delay = (random.random() + 0.5) * delay - delay = min(delay, self.max_delay) + random_delay = min( + (random.random() + 0.5) * delay, + self.max_delay, + ) logger.info( - f"Attempt {attempt + 1} failed: {e}. Retrying in {delay} seconds...", + f"Attempt {attempt + 1} failed: {e}. Retrying in {random_delay} seconds...", ) - time.sleep(delay) + time.sleep(random_delay) delay *= 2