mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
GH-83658: make multiprocessing.Pool raise an exception if maxtasksperchild is not None or a positive int (GH-93364) (GH-93924)
Closes GH-83658.
(cherry picked from commit e37a158725
)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
5e30ba1577
commit
2d33d217aa
3 changed files with 9 additions and 0 deletions
|
@ -203,6 +203,9 @@ class Pool(object):
|
||||||
processes = os.cpu_count() or 1
|
processes = os.cpu_count() or 1
|
||||||
if processes < 1:
|
if processes < 1:
|
||||||
raise ValueError("Number of processes must be at least 1")
|
raise ValueError("Number of processes must be at least 1")
|
||||||
|
if maxtasksperchild is not None:
|
||||||
|
if not isinstance(maxtasksperchild, int) or maxtasksperchild <= 0:
|
||||||
|
raise ValueError("maxtasksperchild must be a positive int or None")
|
||||||
|
|
||||||
if initializer is not None and not callable(initializer):
|
if initializer is not None and not callable(initializer):
|
||||||
raise TypeError('initializer must be a callable')
|
raise TypeError('initializer must be a callable')
|
||||||
|
|
|
@ -2805,6 +2805,11 @@ class _TestPoolWorkerLifetime(BaseTestCase):
|
||||||
for (j, res) in enumerate(results):
|
for (j, res) in enumerate(results):
|
||||||
self.assertEqual(res.get(), sqr(j))
|
self.assertEqual(res.get(), sqr(j))
|
||||||
|
|
||||||
|
def test_pool_maxtasksperchild_invalid(self):
|
||||||
|
for value in [0, -1, 0.5, "12"]:
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
multiprocessing.Pool(3, maxtasksperchild=value)
|
||||||
|
|
||||||
def test_worker_finalization_via_atexit_handler_of_multiprocessing(self):
|
def test_worker_finalization_via_atexit_handler_of_multiprocessing(self):
|
||||||
# tests cases against bpo-38744 and bpo-39360
|
# tests cases against bpo-38744 and bpo-39360
|
||||||
cmd = '''if 1:
|
cmd = '''if 1:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make :class:`multiprocessing.Pool` raise an exception if ``maxtasksperchild`` is not ``None`` or a positive int.
|
Loading…
Add table
Add a link
Reference in a new issue