Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d86ef05

Browse files
committed
Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor doesn't exist.
Patch by Claudiu Popa.
1 parent c3a7f18 commit d86ef05

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

Doc/library/compileall.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ Public functions
142142
The argument *workers* specifies how many workers are used to
143143
compile files in parallel. The default is to not use multiple workers.
144144
If the platform can't use multiple workers and *workers* argument is given,
145-
then a :exc:`NotImplementedError` will be raised.
146-
If *workers* is lower than ``0``, a :exc:`ValueError` will be raised.
145+
then sequential compilation will be used as a fallback. If *workers* is
146+
lower than ``0``, a :exc:`ValueError` will be raised.
147147

148148
.. versionchanged:: 3.2
149149
Added the *legacy* and *optimize* parameter.

Lib/compileall.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
6969
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels,
7070
ddir=ddir)
7171
success = 1
72-
if workers is not None and workers != 1:
72+
if workers is not None and workers != 1 and ProcessPoolExecutor is not None:
7373
if workers < 0:
7474
raise ValueError('workers must be greater or equal to 0')
75-
if ProcessPoolExecutor is None:
76-
raise NotImplementedError('multiprocessing support not available')
7775

7876
workers = workers or None
7977
with ProcessPoolExecutor(max_workers=workers) as executor:

Lib/test/test_compileall.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def test_compile_one_worker(self, compile_file_mock, pool_mock):
136136
self.assertTrue(compile_file_mock.called)
137137

138138
@mock.patch('compileall.ProcessPoolExecutor', new=None)
139-
def test_compile_missing_multiprocessing(self):
140-
with self.assertRaisesRegex(NotImplementedError,
141-
"multiprocessing support not available"):
142-
compileall.compile_dir(self.directory, quiet=True, workers=5)
139+
@mock.patch('compileall.compile_file')
140+
def test_compile_missing_multiprocessing(self, compile_file_mock):
141+
compileall.compile_dir(self.directory, quiet=True, workers=5)
142+
self.assertTrue(compile_file_mock.called)
143143

144144
class EncodingTest(unittest.TestCase):
145145
"""Issue 6716: compileall should escape source code when printing errors

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Core and Builtins
1515
Library
1616
-------
1717

18+
- Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor
19+
doesn't exist. Patch by Claudiu Popa.
20+
1821
- Issue #23008: Fixed resolving attributes with boolean value is False in pydoc.
1922

2023
- Fix asyncio issue 235: LifoQueue and PriorityQueue's put didn't

0 commit comments

Comments
 (0)