summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrian Quinlan <brian@sweetapp.com>2014-05-17 20:51:10 (GMT)
committerBrian Quinlan <brian@sweetapp.com>2014-05-17 20:51:10 (GMT)
commit20efceb75790f2a40fad449fd92a6b3d8fe40c8b (patch)
treef40a8391cb82646bfc6a26ae857a461732ac6dfa /Lib
parent120e8edfb8b0e477dbe351c14e18803301df48ac (diff)
downloadcpython-20efceb75790f2a40fad449fd92a6b3d8fe40c8b.zip
cpython-20efceb75790f2a40fad449fd92a6b3d8fe40c8b.tar.gz
cpython-20efceb75790f2a40fad449fd92a6b3d8fe40c8b.tar.bz2
Issue #21362: concurrent.futures does not validate that max_workers is proper
Diffstat (limited to 'Lib')
-rw-r--r--Lib/concurrent/futures/process.py3
-rw-r--r--Lib/concurrent/futures/thread.py3
-rw-r--r--Lib/test/test_concurrent_futures.py7
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index 07b5225..1299390 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -334,6 +334,9 @@ class ProcessPoolExecutor(_base.Executor):
if max_workers is None:
self._max_workers = os.cpu_count() or 1
else:
+ if max_workers <= 0:
+ raise ValueError("max_workers must be greater than 0")
+
self._max_workers = max_workers
# Make the call queue slightly larger than the number of processes to
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index f9beb0f..8d6081c 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -87,6 +87,9 @@ class ThreadPoolExecutor(_base.Executor):
max_workers: The maximum number of threads that can be used to
execute the given calls.
"""
+ if max_workers <= 0:
+ raise ValueError("max_workers must be greater than 0")
+
self._max_workers = max_workers
self._work_queue = queue.Queue()
self._threads = set()
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index c74b2ca..55254b5 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -425,6 +425,13 @@ class ExecutorTest:
self.assertTrue(collected,
"Stale reference not collected within timeout.")
+ def test_max_workers_negative(self):
+ for number in (0, -1):
+ with self.assertRaisesRegexp(ValueError,
+ "max_workers must be greater "
+ "than 0"):
+ self.executor_type(max_workers=number)
+
class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, unittest.TestCase):
def test_map_submits_without_iteration(self):