summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-04-22 09:39:19 +0300
committerBerker Peksag <berker.peksag@gmail.com>2015-04-22 09:39:19 +0300
commitd86ef05a02e820adfd1e3a11cd56d3444d9aa2c9 (patch)
tree30787c75b3ea3d03e90022ca6a42f539403e1250
parentc3a7f181008fef91b5a5977b370271ce3f7f75b0 (diff)
downloadcpython-git-d86ef05a02e820adfd1e3a11cd56d3444d9aa2c9.tar.gz
Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor doesn't exist.
Patch by Claudiu Popa.
-rw-r--r--Doc/library/compileall.rst4
-rw-r--r--Lib/compileall.py4
-rw-r--r--Lib/test/test_compileall.py8
-rw-r--r--Misc/NEWS3
4 files changed, 10 insertions, 9 deletions
diff --git a/Doc/library/compileall.rst b/Doc/library/compileall.rst
index 57f4804979..0325f1ac89 100644
--- a/Doc/library/compileall.rst
+++ b/Doc/library/compileall.rst
@@ -142,8 +142,8 @@ Public functions
The argument *workers* specifies how many workers are used to
compile files in parallel. The default is to not use multiple workers.
If the platform can't use multiple workers and *workers* argument is given,
- then a :exc:`NotImplementedError` will be raised.
- If *workers* is lower than ``0``, a :exc:`ValueError` will be raised.
+ then sequential compilation will be used as a fallback. If *workers* is
+ lower than ``0``, a :exc:`ValueError` will be raised.
.. versionchanged:: 3.2
Added the *legacy* and *optimize* parameter.
diff --git a/Lib/compileall.py b/Lib/compileall.py
index aeaaf8e9ce..64c0a9abdb 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -69,11 +69,9 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels,
ddir=ddir)
success = 1
- if workers is not None and workers != 1:
+ if workers is not None and workers != 1 and ProcessPoolExecutor is not None:
if workers < 0:
raise ValueError('workers must be greater or equal to 0')
- if ProcessPoolExecutor is None:
- raise NotImplementedError('multiprocessing support not available')
workers = workers or None
with ProcessPoolExecutor(max_workers=workers) as executor:
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index 07756f6874..2053304e6b 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -136,10 +136,10 @@ class CompileallTests(unittest.TestCase):
self.assertTrue(compile_file_mock.called)
@mock.patch('compileall.ProcessPoolExecutor', new=None)
- def test_compile_missing_multiprocessing(self):
- with self.assertRaisesRegex(NotImplementedError,
- "multiprocessing support not available"):
- compileall.compile_dir(self.directory, quiet=True, workers=5)
+ @mock.patch('compileall.compile_file')
+ def test_compile_missing_multiprocessing(self, compile_file_mock):
+ compileall.compile_dir(self.directory, quiet=True, workers=5)
+ self.assertTrue(compile_file_mock.called)
class EncodingTest(unittest.TestCase):
"""Issue 6716: compileall should escape source code when printing errors
diff --git a/Misc/NEWS b/Misc/NEWS
index 0c38481351..83a8da83a9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
Library
-------
+- Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor
+ doesn't exist. Patch by Claudiu Popa.
+
- Issue #23008: Fixed resolving attributes with boolean value is False in pydoc.
- Fix asyncio issue 235: LifoQueue and PriorityQueue's put didn't