OLD | NEW |
---|---|
1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Module containing methods/classes related to running parallel test jobs.""" | 5 """Module containing methods/classes related to running parallel test jobs.""" |
6 | 6 |
7 import multiprocessing | 7 import multiprocessing |
8 import sys | 8 import sys |
9 import time | 9 import time |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 def GetCurrentActiveCount(): | 57 def GetCurrentActiveCount(): |
58 """Returns the (number of active jobs, first active job).""" | 58 """Returns the (number of active jobs, first active job).""" |
59 active_count = 0 | 59 active_count = 0 |
60 active_job = None | 60 active_job = None |
61 for parallel_job in parallel_jobs: | 61 for parallel_job in parallel_jobs: |
62 if parallel_job.is_alive(): | 62 if parallel_job.is_alive(): |
63 active_count += 1 | 63 active_count += 1 |
64 if not active_job: | 64 if not active_job: |
65 active_job = parallel_job | 65 active_job = parallel_job |
66 | 66 |
67 return (active_count, parallel_job) | 67 return (active_count, active_job) |
dgarrett
2011/04/14 00:08:17
This looks like a valid, but separate change. Does
| |
68 | 68 |
69 start_time = time.time() | 69 start_time = time.time() |
70 while (time.time() - start_time) < cls.MAX_TIMEOUT_SECONDS: | 70 while (time.time() - start_time) < cls.MAX_TIMEOUT_SECONDS: |
71 (active_count, active_job) = GetCurrentActiveCount() | 71 (active_count, active_job) = GetCurrentActiveCount() |
72 if active_count == 0: | 72 if active_count == 0: |
73 return | 73 return |
74 else: | 74 else: |
75 print >> sys.stderr, ( | 75 print >> sys.stderr, ( |
76 'Process Pool Active: Waiting on %d/%d jobs to complete' % | 76 'Process Pool Active: Waiting on %d/%d jobs to complete' % |
77 (active_count, len(parallel_jobs))) | 77 (active_count, len(parallel_jobs))) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 output_array.append(output) | 136 output_array.append(output) |
137 | 137 |
138 # We use a semaphore to ensure we don't run more jobs than required. | 138 # We use a semaphore to ensure we don't run more jobs than required. |
139 # After each parallel_job finishes, it releases (increments semaphore). | 139 # After each parallel_job finishes, it releases (increments semaphore). |
140 for next_parallel_job in parallel_jobs: | 140 for next_parallel_job in parallel_jobs: |
141 job_start_semaphore.acquire(block=True) | 141 job_start_semaphore.acquire(block=True) |
142 next_parallel_job.start() | 142 next_parallel_job.start() |
143 | 143 |
144 ParallelJob.WaitUntilJobsComplete(parallel_jobs) | 144 ParallelJob.WaitUntilJobsComplete(parallel_jobs) |
145 return [output.get() for output in output_array] | 145 return [output.get() for output in output_array] |
OLD | NEW |