jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Improve throttle module

- remove dropdelay and releasepid attributes
- introduce a new expiry class attribute instead which holds an
appropriate constant
- change checkdelay attribute to Throttle class attribute

Change-Id: I3a11ca0e705d3444ace46515264383ae3207a15d
---
M pywikibot/throttle.py
1 file changed, 61 insertions(+), 24 deletions(-)

diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 2241059..0daf9fc 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -21,12 +21,13 @@
FORMAT_LINE = '{module_id} {pid} {time} {site}\n'
ProcEntry = namedtuple('ProcEntry', ['module_id', 'pid', 'time', 'site'])

-# global process identifier
-#
-# When the first Throttle is instantiated, it will set this variable to a
-# positive integer, which will apply to all throttle objects created by this
-# process.
-pid = False
+pid: Union[bool, int] = False
+"""global process identifier
+
+When the first Throttle is instantiated, it will set this variable to a
+positive integer, which will apply to all throttle objects created by
+this process.
+"""


class Throttle:
@@ -46,6 +47,11 @@
:param writedelay: The write delay
"""

+ # Check throttle file again after this many seconds:
+ checkdelay: int = 300
+ # The number of seconds entries of a process need to be counted
+ expiry: int = 600
+
def __init__(self, site: Union['pywikibot.site.BaseSite', str], *,
mindelay: Optional[int] = None,
maxdelay: Optional[int] = None,
@@ -63,15 +69,6 @@
self.last_write = 0
self.next_multiplicity = 1.0

- # Check logfile again after this many seconds:
- self.checkdelay = 300
-
- # Ignore processes that have not made a check in this many seconds:
- self.dropdelay = 600
-
- # Free the process id after this many seconds:
- self.releasepid = 1200
-
self.retry_after = 0 # set by http.request
self.delay = 0
self.checktime = 0
@@ -83,13 +80,39 @@
@property
@deprecated(since='6.2')
def multiplydelay(self) -> bool:
- """DEPRECATED attribute."""
+ """DEPRECATED attribute.
+
+ .. deprecated:: 6.2
+ """
return True

@multiplydelay.setter
@deprecated(since='6.2')
def multiplydelay(self) -> None:
- """DEPRECATED attribute setter."""
+ """DEPRECATED attribute setter.
+
+ .. deprecated:: 6.2
+ """
+
+ @property
+ @deprecated('expiry', since='8.4')
+ def dropdelay(self):
+ """Ignore processes that have not made a check in this many seconds.
+
+ .. deprecated:: 8.4
+ use *expiry* instead.
+ """
+ return self.expiry
+
+ @property
+ @deprecated('expiry', since='8.4')
+ def releasepid(self):
+ """Free the process id after this many seconds.
+
+ .. deprecated:: 8.4
+ use *expiry* instead.
+ """
+ return self.expiry

@staticmethod
def _module_hash(module=None) -> str:
@@ -152,12 +175,12 @@
now = time.time()
for proc in self._read_file(raise_exc=True):
used_pids.add(proc.pid)
- if now - proc.time > self.releasepid:
- continue # process has expired, drop from file
- if now - proc.time <= self.dropdelay \
- and proc.site == mysite \
- and proc.pid != pid:
+ if now - proc.time > self.expiry:
+ continue # process has expired, drop from file
+
+ if proc.site == mysite and proc.pid != pid:
count += 1
+
if proc.site != mysite or proc.pid != pid:
processes.append(proc)

@@ -178,8 +201,8 @@
self._write_file(sorted(processes, key=lambda p: p.pid))

self.process_multiplicity = count
- pywikibot.log('Found {} {} processes running, including this one.'
- .format(count, mysite))
+ pywikibot.log(f'Found {count} {mysite} processes running,'
+ ' including this one.')

def setDelays(
self,

To view, visit change 949018. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3a11ca0e705d3444ace46515264383ae3207a15d
Gerrit-Change-Number: 949018
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged