diff -r 462470859e57 Doc/library/concurrent.futures.rst --- a/Doc/library/concurrent.futures.rst Sat Apr 26 19:01:47 2014 -0400 +++ b/Doc/library/concurrent.futures.rst Sun Apr 27 19:26:12 2014 +0300 @@ -175,6 +175,8 @@ An :class:`Executor` subclass that executes calls asynchronously using a pool of at most *max_workers* processes. If *max_workers* is ``None`` or not given, it will default to the number of processors on the machine. + If *max_workers* is lower or equal to ``0``, than a :exc:`ValueError` + will be raised. .. versionchanged:: 3.3 When one of the worker processes terminates abruptly, a diff -r 462470859e57 Lib/concurrent/futures/process.py --- a/Lib/concurrent/futures/process.py Sat Apr 26 19:01:47 2014 -0400 +++ b/Lib/concurrent/futures/process.py Sun Apr 27 19:26:12 2014 +0300 @@ -334,6 +334,9 @@ 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 -r 462470859e57 Lib/concurrent/futures/thread.py --- a/Lib/concurrent/futures/thread.py Sat Apr 26 19:01:47 2014 -0400 +++ b/Lib/concurrent/futures/thread.py Sun Apr 27 19:26:12 2014 +0300 @@ -87,6 +87,9 @@ 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 -r 462470859e57 Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py Sat Apr 26 19:01:47 2014 -0400 +++ b/Lib/test/test_concurrent_futures.py Sun Apr 27 19:26:12 2014 +0300 @@ -437,6 +437,13 @@ self.executor.shutdown(wait=True) self.assertCountEqual(finished, range(10)) + 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 ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, unittest.TestCase): def test_killed_child(self): @@ -451,6 +458,16 @@ # Submitting other jobs fails as well. self.assertRaises(BrokenProcessPool, self.executor.submit, pow, 2, 8) + def test_max_workers_negative(self): + for number in (0, -1): + with self.assertRaisesRegexp(ValueError, + "max_workers must be greater " + "than 0"): + try: + self.executor_type(max_workers=number) + except NotImplementedError as e: + self.skipTest(str(e)) + class FutureTests(unittest.TestCase): def test_done_callback_with_result(self):