Skip to content

Commit e37a158

Browse files
authored
GH-83658: make multiprocessing.Pool raise an exception if maxtasksperchild is not None or a positive int (GH-93364)
Closes #83658.
1 parent 38af903 commit e37a158

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/multiprocessing/pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def __init__(self, processes=None, initializer=None, initargs=(),
203203
processes = os.cpu_count() or 1
204204
if processes < 1:
205205
raise ValueError("Number of processes must be at least 1")
206+
if maxtasksperchild is not None:
207+
if not isinstance(maxtasksperchild, int) or maxtasksperchild <= 0:
208+
raise ValueError("maxtasksperchild must be a positive int or None")
206209

207210
if initializer is not None and not callable(initializer):
208211
raise TypeError('initializer must be a callable')

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,11 @@ def test_pool_worker_lifetime_early_close(self):
28632863
for (j, res) in enumerate(results):
28642864
self.assertEqual(res.get(), sqr(j))
28652865

2866+
def test_pool_maxtasksperchild_invalid(self):
2867+
for value in [0, -1, 0.5, "12"]:
2868+
with self.assertRaises(ValueError):
2869+
multiprocessing.Pool(3, maxtasksperchild=value)
2870+
28662871
def test_worker_finalization_via_atexit_handler_of_multiprocessing(self):
28672872
# tests cases against bpo-38744 and bpo-39360
28682873
cmd = '''if 1:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :class:`multiprocessing.Pool` raise an exception if ``maxtasksperchild`` is not ``None`` or a positive int.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy