throttle — Slow Down Wiki I/O#
Mechanics to slow down wiki read and/or write rate.
- class throttle.ProcEntry(module_id, pid, time, site)#
Bases:
tupleCreate new instance of ProcEntry(module_id, pid, time, site)
- property module_id#
Alias for field number 0
- property pid#
Alias for field number 1
- property site#
Alias for field number 3
- property time#
Alias for field number 2
- class throttle.Throttle(site, *, mindelay=None, maxdelay=None, writedelay=None)[source]#
Bases:
objectControl rate of access to wiki server.
Calling this object blocks the calling thread until at least
'delay'seconds have passed since the previous call.Each Site initiates one Throttle object (
site.throttle) to control the rate of access.- Parameters:
site (Union[pywikibot.site.BaseSite, str]) – site or sitename for this Throttle. If site is an empty string, it will not be written to the throttle.ctrl file.
mindelay (Optional[int]) – The minimal delay, also used for read access
maxdelay (Optional[int]) – The maximal delay
writedelay (Optional[Union[int, float]]) – The write delay
- checkMultiplicity()[source]#
Count running processes for site and set process_multiplicity.
Changed in version 7.0: process is not written to throttle.ctrl file is site is empty
- Return type:
None
- getDelay(write=False)[source]#
Return the actual delay, accounting for multiple processes.
This value is the maximum wait between reads/writes, not taking into account of how much time has elapsed since the last access.
- Parameters:
write (bool) –
- get_pid(module)[source]#
Get the global pid if the module is running multiple times.
- Parameters:
module (str) –
- Return type:
int
- lag(lagtime=None)[source]#
Seize the throttle lock due to server lag.
Usually the
self.retry-aftervalue fromresponse_headerof the last request if available which will be used for wait time. Otherwiselagtimefrom apimaxlagis used. If neitherself.retry_afternorlagtimeis set, fallback toconfig.retry_wait.If the
lagtimeis disproportionately high compared toself.retry_aftervalue, the wait time will be increased.This method is used by
api.request. It will prevent any thread from accessing this site.- Parameters:
lagtime (Optional[float]) – The time to wait for the next request which is the last
maxlagtime from api warning. This is only used as a fallback ifself.retry_afterisn’t set.- Return type:
None
- property multiplydelay: bool#
Deprecated.
DEPRECATED attribute.
- setDelays(delay=None, writedelay=None, absolute=False)[source]#
Set the nominal delays in seconds. Defaults to config values.
- Parameters:
absolute (bool) –
- Return type:
None