jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/567492 )
Change subject: [IMPR] Timeout retries due to maxlag ......................................................................
[IMPR] Timeout retries due to maxlag
Currently there is no Timeout due to maxlag parameter. With this patch a Timeout is implemented after 5 or more retries given by config.config.max_retries.
Bug: T242081 Change-Id: Iec6db16b2e4efb7bbede6ba09b05b43021aa0b26 --- M pywikibot/data/api.py 1 file changed, 10 insertions(+), 5 deletions(-)
Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 8e9132b..ee4b6bf 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1971,7 +1971,7 @@ """ self._add_defaults() use_get = self._use_get() - + retries = 0 while True: paramstring = self._http_param_string()
@@ -2023,11 +2023,13 @@ continue
if code == 'maxlag': - lag = lagpattern.search(info) + retries += 1 + if retries > max(5, pywikibot.config.max_retries): + break pywikibot.log('Pausing due to database lag: ' + info) - if lag: - lag = lag.group('lag') - self.site.throttle.lag(int(lag or 0)) + lag = lagpattern.search(info) + lag = int(lag.group('lag')) if lag else 0 + self.site.throttle.lag(lag * retries) continue
elif code == 'help' and self.action == 'help': @@ -2086,6 +2088,9 @@ except TypeError: raise RuntimeError(result)
+ raise TimeoutError( + 'Maximum retries attempted due to maxlag without success.') + def wait(self): """Determine how long to wait after a failed request.""" self.max_retries -= 1
pywikibot-commits@lists.wikimedia.org