From f64a0cffca141fa0a8f1138b5f069ea0da446c9f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2011 17:54:33 +0200 Subject: [PATCH] Issue #12285: multiprocessing.Pool() raises a ValueError if the number of processes if negative or null. --- Lib/multiprocessing/pool.py | 2 ++ Lib/test/test_multiprocessing.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py index 862a60e92cf..c66876a856c 100644 --- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -125,6 +125,8 @@ class Pool(object): processes = cpu_count() except NotImplementedError: processes = 1 + if processes < 1: + raise ValueError("Number of processes must be at least 1") if initializer is not None and not hasattr(initializer, '__call__'): raise TypeError('initializer must be a callable') diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index fe19de03715..de5e46a1e47 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1085,6 +1085,9 @@ class _TestPool(BaseTestCase): self.assertEqual(sorted(it), map(sqr, range(1000))) def test_make_pool(self): + self.assertRaises(ValueError, multiprocessing.Pool, -1) + self.assertRaises(ValueError, multiprocessing.Pool, 0) + p = multiprocessing.Pool(3) self.assertEqual(3, len(p._pool)) p.close()