jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1235846?usp=email )
Change subject: throttle: Enhance waittime() and update throttle docstrings
......................................................................
throttle: Enhance waittime() and update throttle docstrings
- waittime(): for read requests, consider both last_read and last_write
timestamps, using the later one to calculate remaining delay.
- Comments updated to describe API requests instead of pages,
clarifying minthrottle/maxthrottle behavior and multi-bot
scenarios.
Bug: T414170
Change-Id: If61750a985699bbeb4f5712c0b958cb685503043
---
M pywikibot/config.py
M pywikibot/throttle.py
2 files changed, 15 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 78c3fb0..7b70c59 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -702,10 +702,11 @@
# ############# SETTINGS TO AVOID SERVER OVERLOAD ##############
-# Slow down the robot such that it never requests a second page within
-# 'minthrottle' seconds. This can be lengthened if the server is slow,
-# but never more than 'maxthrottle' seconds. However - if you are running
-# more than one bot in parallel the times are lengthened.
+# Slow down the bot so that it never issues two API requests within
+# 'minthrottle' seconds. This delay may be increased if the server is slow
+# or requests are limited by bot policy, but never beyond 'maxthrottle'
+# seconds. When running multiple bots in parallel, the effective waiting
+# time is increased accordingly.
#
# 'maxlag' is used to control the rate of server access (see below).
# Set minthrottle to non-zero to use a throttle on read access.
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index d0fd51f..fe97b42 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -301,13 +301,22 @@
def waittime(self, write: bool = False):
"""Return waiting time in seconds.
+ .. versionchanged:: 11.0
+ Use the latest request timestamp for read operation.
+
The result is for a query that would be made right now.
"""
# Take the previous requestsize in account calculating the desired
# delay this time
thisdelay = self.get_delay(write=write)
now = time.time()
- ago = now - (self.last_write if write else self.last_read)
+
+ if write:
+ last = self.last_write
+ else:
+ last = max(self.last_read, self.last_write)
+
+ ago = now - last
return max(0.0, thisdelay - ago)
def drop(self) -> None:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1235846?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If61750a985699bbeb4f5712c0b958cb685503043
Gerrit-Change-Number: 1235846
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]