(self)
return compile_function
Builds a function object usable as distutils.ccompiler.CCompiler.compile.
Builds a function object usable as distutils.ccompiler.CCompiler.compile.
Builds a function object usable as distutils . ccompiler . CCompiler . compile .
def function(self):
        """
        Builds a function object usable as distutils.ccompiler.CCompiler.compile.
        """

        def compile_function(
            compiler,
            sources,
            output_dir=None,
            macros=None,
            include_dirs=None,
            debug=0,
            extra_preargs=None,
            extra_postargs=None,
            depends=None,
        ):

            # These lines are directly from distutils.ccompiler.CCompiler
            macros, objects, extra_postargs, pp_opts, build = compiler._setup_compile(
                output_dir, macros, include_dirs, sources, depends, extra_postargs
            )
            cc_args = compiler._get_cc_args(pp_opts, debug, extra_preargs)

            # The number of threads; start with default.
            threads = self.default

            # Determine the number of compilation threads, unless set by an environment variable.
            if self.envvar is not None:
                threads = int(os.environ.get(self.envvar, self.default))

            def _single_compile(obj):
                try:
                    src, ext = build[obj]
                except KeyError:
                    return
                compiler._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)

            try:
                import multiprocessing
                from multiprocessing.pool import ThreadPool
            except ImportError:
                threads = 1

            if threads == 0:
                try:
                    threads = multiprocessing.cpu_count()
                    threads = self.max if self.max and self.max < threads else threads
                except NotImplementedError:
                    threads = 1

            if threads > 1:
                for _ in ThreadPool(threads).imap_unordered(_single_compile, objects):
                    pass
            else:
                for ob in objects:
                    _single_compile(ob)

            return objects

        return compile_function
def function ( self ) : def compile_function ( compiler , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None , ) : # These lines are directly from distutils.ccompiler.CCompiler macros , objects , extra_postargs , pp_opts , build = compiler . _setup_compile ( output_dir , macros , include_dirs , sources , depends , extra_postargs ) cc_args = compiler . _get_cc_args ( pp_opts , debug , extra_preargs ) # The number of threads; start with default. threads = self . default # Determine the number of compilation threads, unless set by an environment variable. if self . envvar is not None : threads = int ( os . environ . get ( self . envvar , self . default ) ) def _single_compile ( obj ) : try : src , ext = build [ obj ] except KeyError : return compiler . _compile ( obj , src , ext , cc_args , extra_postargs , pp_opts ) try : import multiprocessing from multiprocessing . pool import ThreadPool except ImportError : threads = 1 if threads == 0 : try : threads = multiprocessing . cpu_count ( ) threads = self . max if self . max and self . max < threads else threads except NotImplementedError : threads = 1 if threads > 1 : for _ in ThreadPool ( threads ) . imap_unordered ( _single_compile , objects ) : pass else : for ob in objects : _single_compile ( ob ) return objects return compile_function