From 387689da005389dd7de28477bfe9273e691234b2 Mon Sep 17 00:00:00 2001 From: Adam Holmberg Date: Fri, 14 Aug 2015 14:49:05 -0500 Subject: [PATCH] Parallel build mechanisms for faster dev builds --- setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5f563cef..a1cd3c63 100644 --- a/setup.py +++ b/setup.py @@ -173,6 +173,8 @@ try_cython = try_extensions and "--no-cython" not in sys.argv and not is_pypy an sys.argv = [a for a in sys.argv if a not in ("--no-murmur3", "--no-libev", "--no-cython", "--no-extensions")] +build_concurrency = int(os.environ.get('CASS_DRIVER_BUILD_CONCURRENCY', '0')) + class build_extensions(build_ext): @@ -234,6 +236,15 @@ On OSX, via homebrew: sys.stderr.write('%s\n' % str(exc)) warnings.warn(self.error_message % "C extensions.") + def build_extensions(self): + if build_concurrency > 1: + self.check_extensions_list(self.extensions) + + import multiprocessing.pool + multiprocessing.pool.ThreadPool(processes=build_concurrency).map(self.build_extension, self.extensions) + else: + build_ext.build_extensions(self) + def build_extension(self, ext): try: build_ext.build_extension(self, ext) @@ -264,8 +275,9 @@ On OSX, via homebrew: [Extension('cassandra.%s' % m, ['cassandra/%s.py' % m], extra_compile_args=compile_args) for m in cython_candidates], + nthreads=build_concurrency, exclude_failures=True)) - self.extensions.extend(cythonize("cassandra/*.pyx")) + self.extensions.extend(cythonize("cassandra/*.pyx", nthreads=build_concurrency)) except Exception: sys.stderr.write("Cython is not available. Not compiling core driver files as extensions (optional).")