美文网首页
retrying处理Python异常

retrying处理Python异常

作者: 弦好想断 | 来源:发表于2022-03-04 17:47 被阅读0次

retrying处理Python异常

https://mp.weixin.qq.com/s/j9vqFQxVIKgECnE0N-bD9A

import random
from retrying import retry

@retry(stop_max_attempt_number=5)
def do_something_unreliable():
    if random.randint(0, 10) > 1:
        print("just have a test")
        raise IOError("raise exception!")
    else:
        return "good job!"

print(do_something_unreliable())

相关文章

网友评论

      本文标题:retrying处理Python异常

      本文链接:https://www.haomeiwen.com/subject/saebtrtx.html