614 # |
613 # |
615 # We now have a possibly large number of test suites to run, so we want to |
614 # We now have a possibly large number of test suites to run, so we want to |
616 # run them in parallel. We're going to spin up a number of worker threads |
615 # run them in parallel. We're going to spin up a number of worker threads |
617 # that will run our test jobs for us. |
616 # that will run our test jobs for us. |
618 # |
617 # |
619 # XXX Need to figure out number of CPUs without the multiprocessing |
|
620 # dependency since multiprocessing is not standard `till Python 2.6 |
|
621 # |
|
622 input_queue = Queue.Queue(0) |
618 input_queue = Queue.Queue(0) |
623 output_queue = Queue.Queue(0) |
619 output_queue = Queue.Queue(0) |
624 |
620 |
625 jobs = 0 |
621 jobs = 0 |
626 threads=[] |
622 threads=[] |
627 |
623 |
628 processors = multiprocessing.cpu_count() |
624 # |
|
625 # In Python 2.6 you can just use multiprocessing module, but we don't want |
|
626 # to introduce that dependency yet; so we jump through a few hoops. |
|
627 # |
|
628 processors = 1 |
|
629 |
|
630 if 'SC_NPROCESSORS_ONLN'in os.sysconf_names: |
|
631 processors = os.sysconf('SC_NPROCESSORS_ONLN') |
|
632 else: |
|
633 proc = subprocess.Popen("sysctl -n hw.ncpu", shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
634 stdout_results, stderr_results = proc.communicate() |
|
635 if len(stderr_results) == 0: |
|
636 processors = int(stdout_results) |
|
637 |
|
638 # |
|
639 # Now, spin up one thread per processor which will eventually mean one test |
|
640 # per processor running concurrently. |
|
641 # |
629 for i in range(processors): |
642 for i in range(processors): |
630 thread = worker_thread(input_queue, output_queue) |
643 thread = worker_thread(input_queue, output_queue) |
631 threads.append(thread) |
644 threads.append(thread) |
632 thread.start() |
645 thread.start() |
633 |
646 |