jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[bugfix] fix the isinstance call in ThreadList initializer

- fix isinstance call which must be (object, classinfo)
- use a wait_time parameter instead of a constant two seconds time
- add documentation

Change-Id: I53aa147f3e0e2d7fcc5451ffc0f9de4b9012faaa
---
M pywikibot/tools/__init__.py
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 8bd43d5..344f15f 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Miscellaneous helper functions (not wiki-dependent)."""
#
-# (C) Pywikibot team, 2008-2019
+# (C) Pywikibot team, 2008-2020
#
# Distributed under the terms of the MIT license.
#
@@ -973,12 +973,19 @@

_logger = 'threadlist'

- def __init__(self, limit=128, *args):
- """Initializer."""
+ def __init__(self, limit=128, wait_time=2, *args):
+ """Initializer.
+
+ @param limit: the number of simultaneous threads
+ @type limit: int
+ @param wait_time: how long to wait if active threads exceeds limit
+ @type wait_time: int or float
+ """
self.limit = limit
+ self.wait_time = wait_time
super(ThreadList, self).__init__(*args)
for item in self:
- if not isinstance(threading.Thread, item):
+ if not isinstance(item, threading.Thread):
raise TypeError("Cannot add '%s' to ThreadList" % type(item))

def active_count(self):
@@ -996,7 +1003,7 @@
if not isinstance(thd, threading.Thread):
raise TypeError("Cannot append '%s' to ThreadList" % type(thd))
while self.active_count() >= self.limit:
- time.sleep(2)
+ time.sleep(self.wait_time)
super(ThreadList, self).append(thd)
thd.start()
debug("thread %d ('%s') started" % (len(self), type(thd)),

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I53aa147f3e0e2d7fcc5451ffc0f9de4b9012faaa
Gerrit-Change-Number: 587689
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Russell Blau <russblau@imapmail.org>
Gerrit-Reviewer: jenkins-bot (75)