mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #12285: multiprocessing.Pool() raises a ValueError if the number of
processes if negative or null.
This commit is contained in:
parent
3fdf9d43e5
commit
f64a0cffca
2 changed files with 5 additions and 0 deletions
|
@ -125,6 +125,8 @@ class Pool(object):
|
||||||
processes = cpu_count()
|
processes = cpu_count()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
processes = 1
|
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__'):
|
if initializer is not None and not hasattr(initializer, '__call__'):
|
||||||
raise TypeError('initializer must be a callable')
|
raise TypeError('initializer must be a callable')
|
||||||
|
|
|
@ -1085,6 +1085,9 @@ class _TestPool(BaseTestCase):
|
||||||
self.assertEqual(sorted(it), map(sqr, range(1000)))
|
self.assertEqual(sorted(it), map(sqr, range(1000)))
|
||||||
|
|
||||||
def test_make_pool(self):
|
def test_make_pool(self):
|
||||||
|
self.assertRaises(ValueError, multiprocessing.Pool, -1)
|
||||||
|
self.assertRaises(ValueError, multiprocessing.Pool, 0)
|
||||||
|
|
||||||
p = multiprocessing.Pool(3)
|
p = multiprocessing.Pool(3)
|
||||||
self.assertEqual(3, len(p._pool))
|
self.assertEqual(3, len(p._pool))
|
||||||
p.close()
|
p.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue