jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/587689 )
Change subject: [bugfix] fix the isinstance call in ThreadList initializer ......................................................................
[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(-)
Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
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)),