中级
实现指数退避重试策略
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
from pyodide.http import open_url
from io import StringIO
circuit_breaker_log_csv = open_url(____).read()
import random
random.seed(____)
def exponential_backoff(____):
delay = min(base * (____ ** attempt), cap)
if jitter: delay = delay * random.uniform(____, ____)
return round(____)
def retry_with_backoff(____):
for attempt in range(____):
result = '____' if attempt >= success_on else '____'
if result == '____':
print(____)
return True
delay = exponential_backoff(____)
print(____)
print(____)
return False
print(____)
retry_with_backoff(____)
print(____)
retry_with_backoff(____)
示例
输入
solve()
期望输出
重试场景1 (success_on=2): attempt=0: FAIL, next retry in 1.139s attempt=1: FAIL, next retry in 1.05s attempt=2: SUCCESS 重试场景2 (success_on=6, should fail): attempt=0: FAIL, next retry in 0.775s attempt=1: FAIL, next retry in 1.446s attempt=2: FAIL, next retry in 4.946s attempt=3: FAIL, next retry in 9.414s attempt=4: FAIL, next retry in 22.275s all 4 retries exhausted
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199