python retrying retry

 

在写业务时, 有个业务需要在return某种情况下,进行重试.

代码类似于下面

from retrying import retry
def verify(self):
try:
return self.verify_1()
except RetryError:
     ....

def retry_if_result(result):
"""Return True if we should retry (in this case when result is 网络故障), False otherwise"""
return '网络故障' in result.errMsg
@retry(stop_max_attempt_number=3, wait_random_min=200, wait_random_max=600,
retry_on_result=retry_if_result)
def verify(self):
  if '***' in data2:
  self.init_login_form(verify=True)
  return None
    ....

 

当重试次数到3次时, 会返回给客户端 result

posted on 2018-09-21 10:40  shidexiao  阅读(857)  评论(0编辑  收藏  举报

导航