|
1 | 1 | #! /usr/bin/env python |
2 | 2 |
|
3 | | -# monkey-patch for parallel compilation |
4 | | -def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None): |
5 | | - # those lines are copied from distutils.ccompiler.CCompiler directly |
6 | | - macros, objects, extra_postargs, pp_opts, build = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs) |
7 | | - cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) |
8 | | - # parallel code |
9 | | - import multiprocessing |
10 | | - import multiprocessing.pool |
11 | | - N=multiprocessing.cpu_count() # number of parallel compilations |
12 | | - def _single_compile(obj): |
13 | | - try: src, ext = build[obj] |
14 | | - except KeyError: return |
15 | | - self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) |
16 | | - # convert to list, imap is evaluated on-demand |
17 | | - try: |
18 | | - pool = multiprocessing.pool.ThreadPool(N) |
19 | | - list(pool.imap(_single_compile,objects)) |
20 | | - except KeyboardInterrupt as e: |
21 | | - print "Caught KeyboardInterrupt, terminating workers" |
22 | | - pool.terminate() |
23 | | - raise e |
24 | | - return objects |
25 | | -import distutils.ccompiler |
26 | | -distutils.ccompiler.CCompiler.compile=parallelCCompile |
27 | 3 | from distutils import sysconfig |
28 | 4 | from setuptools import setup, Extension |
29 | 5 | import os |
|
0 commit comments