jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1337908?usp=email )

Change subject: threading: Reject invalid ThreadList limits
......................................................................

threading: Reject invalid ThreadList limits

A zero or negative thread limit makes append() wait indefinitely because
its active thread count can never fall below the limit.

Validate the limit when constructing the pool. Require a positive
integer and reject booleans so invalid configurations fail immediately.

Change-Id: I72bea823a4a0b1d9fbb2ec5bbb920f9d56549ae3
---
M pywikibot/tools/threading.py
1 file changed, 10 insertions(+), 1 deletion(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/tools/threading.py b/pywikibot/tools/threading.py
index 659ef17..7cd7fe2 100644
--- a/pywikibot/tools/threading.py
+++ b/pywikibot/tools/threading.py
@@ -140,13 +140,22 @@

     .. seealso:: :class:`BoundedPoolExecutor`

-    :param limit: the number of simultaneous threads
+    :param limit: the positive integer number of simultaneous threads
     :param wait_time: how long to wait if active threads exceeds limit
+    :raises TypeError: limit is not an integer or is a boolean
+    :raises ValueError: limit is less than 1
     """

     limit: int = 128  #: :meta private:
     wait_time: float = 2.0  #: :meta private:

+    def __post_init__(self) -> None:
+        """Validate the thread limit."""
+        if not isinstance(self.limit, int) or isinstance(self.limit, bool):
+            raise TypeError("'limit' must be an integer")
+        if self.limit < 1:
+            raise ValueError("Minimum 'limit' is 1")
+
     def active_count(self) -> int:
         """Return the number of alive threads and delete all non-alive ones."""
         cnt = 0

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1337908?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: I72bea823a4a0b1d9fbb2ec5bbb920f9d56549ae3
Gerrit-Change-Number: 1337908
Gerrit-PatchSet: 1
Gerrit-Owner: Mahveotm <[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]

Reply via email to