Skip to content

Commit 64bce1a

Browse files
author
Virgil Dupras
committed
Fix builds with --parallel
Python 3.5's distutils added support for parallel builds, which means that we don't need to monkeypatch it anymore. But more importantly, this monkeypatch made build fail (hang in fact) whenever `--parallel` was passed to `python setup.py build`. This commit fixes the problem by not applying the monkeypatch on python 3.5+ and preserve the old behavior (parallel build by default) by injecting a `parallel` option when it's not specified.
1 parent 69918dc commit 64bce1a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mp_compile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# A monkey patch of the base distutils.ccompiler to use parallel builds
22
# Tested on 2.7, looks to be identical to 3.3.
3+
# Only applied on Python < 3.5 because otherwise, it conflicts with Python's
4+
# own newly-added support for parallel builds.
35

46
from __future__ import print_function
57
from multiprocessing import Pool, cpu_count
@@ -77,4 +79,6 @@ def install():
7779
"%s processes" % MAX_PROCS)
7880

7981

80-
install()
82+
# We monkeypatch only versions earlier than 3.5
83+
if sys.version_info < (3, 5):
84+
install()

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ def finalize_options(self):
205205
if self.debug:
206206
global DEBUG
207207
DEBUG = True
208+
if sys.version_info >= (3, 5) and not self.parallel:
209+
# For Python < 3.5, we monkeypatch distutils to have parallel
210+
# builds. If --parallel (or -j) wasn't specified, we want to
211+
# reproduce the same behavior as before, that is, auto-detect the
212+
# number of jobs.
213+
self.parallel = mp_compile.MAX_PROCS
208214
for x in self.feature:
209215
if getattr(self, 'disable_%s' % x):
210216
setattr(self.feature, x, False)

0 commit comments

Comments
 (0)