jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/572615 )
Change subject: [IMPR] use 'lag' value of 'error' result ......................................................................
[IMPR] use 'lag' value of 'error' result
- maxlag error delivers a 'lag' float value. use this value instead of parsing the info string. - fallback to parsing. Modify the lagpattern to get a float value
Change-Id: I29adaad064cda2e5abc399b3e6beb6035ecd9a48 --- M pywikibot/data/api.py M pywikibot/throttle.py 2 files 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 0702d38..d65c260 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -98,7 +98,7 @@ _logger = 'data.api'
lagpattern = re.compile( - r'Waiting for [\w.: ]+: (?P<lag>\d+)(?:.\d+)? seconds? lagged') + r'Waiting for [\w.: ]+: (?P<lag>\d+(?:.\d+)?) seconds? lagged')
class APIError(Error): @@ -2022,8 +2022,13 @@ if retries > max(5, pywikibot.config.max_retries): break pywikibot.log('Pausing due to database lag: ' + info) - lag = lagpattern.search(info) - lag = int(lag.group('lag')) if lag else 0 + + try: + lag = result['error']['lag'] + except KeyError: + lag = lagpattern.search(info) + lag = float(lag.group('lag')) if lag else 0.0 + self.site.throttle.lag(lag * retries) continue
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index 608f6dc..91b3318 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Mechanics to slow down wiki read and/or write rate.""" # -# (C) Pywikibot team, 2008-2019 +# (C) Pywikibot team, 2008-2020 # # Distributed under the terms of the MIT license. # @@ -299,7 +299,7 @@ @param lagtime: The time to wait for the next request which is the last maxlag time from api warning. This is only used as a fallback if self.retry-after isn't set. - @type lagtime: int + @type lagtime: float """ started = time.time() with self.lock:
pywikibot-commits@lists.wikimedia.org