Skip to content

Commit 5edd76f

Browse files
authored
Parallelize Cython extension compilation (#12576)
1 parent 9e0a117 commit 5edd76f

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGES/12576.packaging.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Parallelized the Cython extension compilation by defaulting
2+
``build_ext.parallel`` to ``os.cpu_count()``, so each module's
3+
``gcc`` invocation now runs concurrently instead of one at a time
4+
-- by :user:`bdraco`.

setup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44

55
from setuptools import Extension, setup
6+
from setuptools.command.build_ext import build_ext
67

78
if sys.version_info < (3, 10):
89
raise RuntimeError("aiohttp 4.x requires Python 3.10+")
@@ -87,8 +88,19 @@
8788
]
8889

8990

91+
class ParallelBuildExt(build_ext):
92+
def build_extensions(self) -> None:
93+
if self.parallel is None:
94+
self.parallel = os.cpu_count() or 1
95+
super().build_extensions()
96+
97+
9098
build_type = "Pure" if NO_EXTENSIONS else "Accelerated"
91-
setup_kwargs = {} if NO_EXTENSIONS else {"ext_modules": extensions}
99+
setup_kwargs = (
100+
{}
101+
if NO_EXTENSIONS
102+
else {"ext_modules": extensions, "cmdclass": {"build_ext": ParallelBuildExt}}
103+
)
92104

93105
print("*********************", file=sys.stderr)
94106
print("* {build_type} build *".format_map(locals()), file=sys.stderr)

0 commit comments

Comments
 (0)