]> granicus.if.org Git - python/commitdiff
Issue #12285: multiprocessing.Pool() raises a ValueError if the number of
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 20 Jun 2011 15:53:35 +0000 (17:53 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 20 Jun 2011 15:53:35 +0000 (17:53 +0200)
processes if negative or null.

Lib/multiprocessing/pool.py
Lib/test/test_multiprocessing.py

index 92170f2ee8ceb75589d29cee0d555aaddf5b010c..e450319d4f4cdaa7dfb17b150b02e6c48b761669 100644 (file)
@@ -148,6 +148,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')
index 2614689bca94cd5a1eb6e2537ff31ca972deb50f..dc41e151bf30e64a1af1869b94f2def399bd27d1 100644 (file)
@@ -1089,6 +1089,9 @@ class _TestPool(BaseTestCase):
         self.assertEqual(sorted(it), list(map(sqr, list(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()