js代码改写py

This commit is contained in:
fengche
2026-01-30 17:47:21 +08:00
parent a482e4ea77
commit aad77378ab
20 changed files with 2649 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import asyncio
import sys
async def execute_with_retry(task, max_retries, delay):
attempts = 0
while attempts < max_retries:
try:
return await task()
except Exception as error:
attempts += 1
print(f"尝试 {attempts} 失败: {error}", file=sys.stderr)
if attempts >= max_retries:
print("已达最大重试次数,任务失败。", file=sys.stderr)
raise
print(f"等待 {delay} 秒后重试...")
await asyncio.sleep(delay)
__all__ = ["execute_with_retry"]