summaryrefslogtreecommitdiffstats
path: root/Lib/compileall.py
diff options
context:
space:
mode:
authorDustin Spicuzza <dustin@virtualroadside.com>2018-11-23 17:06:55 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-11-23 17:06:55 (GMT)
commit1d817e4c8259f49602eefe9729743f6d9d748e8d (patch)
treea61b355b3a005f4f69015f24150af36a393a8b33 /Lib/compileall.py
parent9de363271519e0616f4a7b59427057c4810d3acc (diff)
downloadcpython-1d817e4c8259f49602eefe9729743f6d9d748e8d.zip
cpython-1d817e4c8259f49602eefe9729743f6d9d748e8d.tar.gz
cpython-1d817e4c8259f49602eefe9729743f6d9d748e8d.tar.bz2
bpo-29877: compileall: import ProcessPoolExecutor only when needed (GH-4856)
Importing ProcessPoolExecutor may hang or cause an error when the import accesses urandom on a low resource platform https://bugs.python.org/issue29877
Diffstat (limited to 'Lib/compileall.py')
-rw-r--r--Lib/compileall.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/compileall.py b/Lib/compileall.py
index 7be23a6..aa65c6b 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -16,10 +16,6 @@ import importlib.util
import py_compile
import struct
-try:
- from concurrent.futures import ProcessPoolExecutor
-except ImportError:
- ProcessPoolExecutor = None
from functools import partial
__all__ = ["compile_dir","compile_file","compile_path"]
@@ -70,9 +66,17 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
workers: maximum number of parallel workers
invalidation_mode: how the up-to-dateness of the pyc will be checked
"""
- if workers is not None and workers < 0:
- raise ValueError('workers must be greater or equal to 0')
-
+ ProcessPoolExecutor = None
+ if workers is not None:
+ if workers < 0:
+ raise ValueError('workers must be greater or equal to 0')
+ elif workers != 1:
+ try:
+ # Only import when needed, as low resource platforms may
+ # fail to import it
+ from concurrent.futures import ProcessPoolExecutor
+ except ImportError:
+ workers = 1
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels,
ddir=ddir)
success = True