Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor doesn't exist.
Patch by Claudiu Popa.
diff --git a/Lib/compileall.py b/Lib/compileall.py
index aeaaf8e..64c0a9a 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -69,11 +69,9 @@
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 07756f6..2053304 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -136,10 +136,10 @@
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