]> granicus.if.org Git - python/commitdiff
Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor doesn...
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 22 Apr 2015 06:39:19 +0000 (09:39 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Wed, 22 Apr 2015 06:39:19 +0000 (09:39 +0300)
Patch by Claudiu Popa.

Doc/library/compileall.rst
Lib/compileall.py
Lib/test/test_compileall.py
Misc/NEWS

index 57f4804979a8a8486283735237a15f691eb58cfa..0325f1ac8949fc47accdf0532ed2461c1e07ad21 100644 (file)
@@ -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.
index aeaaf8e9ce1f9a2c60261ebf1d0cc90f55ac7e56..64c0a9abdb67b11d865a7327f8cececa3ac0e767 100644 (file)
@@ -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:
index 07756f6874717ff69be1f4820aab4372301ba302..2053304e6bb343532b92962bc63e870486b6b2b7 100644 (file)
@@ -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
index 0c38481351531717005a57740ba20a042f3adc5f..83a8da83a93349813e7c7dfb45fa29aa28edc8a9 100644 (file)
--- 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