From c39de6d299f1d05b602ba38975e3980167838707 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 18 Apr 2014 13:22:47 -0700 Subject: [PATCH] environment based concurrency limit --- .travis.yml | 2 ++ Tests/run.py | 6 +++++- mp_compile.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f636f223..d2a82e3b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ virtualenv: notifications: irc: "chat.freenode.net#pil" +env: MAX_CONCURRENCY=4 + python: - 2.6 - 2.7 diff --git a/Tests/run.py b/Tests/run.py index 719f8b904..5b4807530 100644 --- a/Tests/run.py +++ b/Tests/run.py @@ -106,7 +106,11 @@ def main(): files = filter_tests(files, python_options, tester_options) - pool = Pool() + try: + max_procs = int(os.environ.get('MAX_CONCURRENCY', cpu_count())) + except: + max_procs = None + pool = Pool(max_procs) results = pool.map(test_one, files) pool.close() pool.join() diff --git a/mp_compile.py b/mp_compile.py index e6cb5c07e..0ff5b4b62 100644 --- a/mp_compile.py +++ b/mp_compile.py @@ -3,6 +3,7 @@ from multiprocessing import Pool, cpu_count from distutils.ccompiler import CCompiler +import os # hideous monkeypatching. but. but. but. def _mp_compile_one(tp): @@ -28,8 +29,13 @@ def _mp_compile(self, sources, output_dir=None, macros=None, self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs) cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) - - pool = Pool() + + + try: + max_procs = int(os.environ.get('MAX_CONCURRENCY', cpu_count())) + except: + max_procs = None + pool = Pool(max_procs) try: print ("Building using %d processes" % pool._processes) except: pass