jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697589 )
Change subject: [IMPR] Double the wait time if ratelimit exceeded ......................................................................
[IMPR] Double the wait time if ratelimit exceeded
Bug: T270912 Change-Id: I85bab755f0caa713bce26acb40c8106489bc6f50 --- M pywikibot/data/api.py 1 file changed, 8 insertions(+), 4 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 932e5ae..48d376d 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -981,6 +981,7 @@ self.max_retries = pywikibot.config.max_retries else: self.max_retries = max_retries + self.current_retries = 0 if retry_wait is None: self.retry_wait = pywikibot.config.retry_wait else: @@ -1871,15 +1872,18 @@
def wait(self, delay=None): """Determine how long to wait after a failed request.""" - self.max_retries -= 1 - if self.max_retries < 0: + self.current_retries += 1 + if self.current_retries > self.max_retries: raise TimeoutError('Maximum retries attempted without success.') + + # double the next wait, but do not exceed config.retry_max seconds delay = delay or self.retry_wait + delay *= 2 ** (self.current_retries - 1) + delay = min(delay, config.retry_max) + pywikibot.warning('Waiting {:.1f} seconds before retrying.' .format(delay)) pywikibot.sleep(delay) - # double the next wait, but do not exceed config.retry_max seconds - self.retry_wait = min(config.retry_max, self.retry_wait * 2)
class CachedRequest(Request):
pywikibot-commits@lists.wikimedia.org