跳至主要內容

retrying - 重试任务

Alex Sun2024年5月27日小于 1 分钟

retrying - 重试任务

1. 项目简介

retrying 是一个 Python 重试任务的工具包。

import random
from retrying import retry

@retry
def do_something_unreliable():
    if random.randint(0, 10) > 1:
        raise IOError("Broken sauce, everything is hosed!!!111one")
    else:
        return "Awesome sauce!"

print(do_something_unreliable())

还可以包含参数:

@retry(stop_max_attempt_number=7)
def stop_after_7_attempts():
    print("Stopping after 7 attempts")

可用参数: