From a4e71dea487750cd13a5a5821df3acee32988bf4 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Sat, 26 Oct 2013 08:22:44 +0000 Subject: [PATCH] lit: handle late multiprocessing errors gracefully This should be a better fix for lit multiprocessing failures, replacing the OpenBSD and FreeBSD workarounds in r193413 and r193457. Reference: http://bugs.python.org/issue3770 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193463 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/main.py | 3 +-- utils/lit/lit/run.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/utils/lit/lit/main.py b/utils/lit/lit/main.py index 9754f2f9239..6f672a01eb3 100755 --- a/utils/lit/lit/main.py +++ b/utils/lit/lit/main.py @@ -111,8 +111,7 @@ def write_test_results(run, lit_config, testing_time, output_path): def main(builtinParameters = {}): # Use processes by default on Unix platforms. isWindows = platform.system() == 'Windows' - # multiprocessing is broken on various BSD Python versions: http://bugs.python.org/issue3770 - useProcessesIsDefault = (not isWindows) and ('BSD' not in platform.system()) + useProcessesIsDefault = not isWindows global options from optparse import OptionParser, OptionGroup diff --git a/utils/lit/lit/run.py b/utils/lit/lit/run.py index 8642ff18927..8aaf52f1aec 100644 --- a/utils/lit/lit/run.py +++ b/utils/lit/lit/run.py @@ -209,16 +209,20 @@ class Run(object): """ # Choose the appropriate parallel execution implementation. - if jobs == 1 or not use_processes or multiprocessing is None: + if jobs != 1 and use_processes and multiprocessing: + try: + task_impl = multiprocessing.Process + queue_impl = multiprocessing.Queue + canceled_flag = multiprocessing.Value('i', 0) + consumer = MultiprocessResultsConsumer(self, display, jobs) + except ImportError: + # Workaround for BSD: http://bugs.python.org/issue3770 + consumer = None + if not consumer: task_impl = threading.Thread queue_impl = queue.Queue canceled_flag = LockedValue(0) consumer = ThreadResultsConsumer(display) - else: - task_impl = multiprocessing.Process - queue_impl = multiprocessing.Queue - canceled_flag = multiprocessing.Value('i', 0) - consumer = MultiprocessResultsConsumer(self, display, jobs) # Create the test provider. provider = TestProvider(self.tests, jobs, queue_impl, canceled_flag)