OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium 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 """ Wrapper that allows method execution in parallel. | 5 """ Wrapper that allows method execution in parallel. |
6 | 6 |
7 This class wraps a list of objects of the same type, emulates their | 7 This class wraps a list of objects of the same type, emulates their |
8 interface, and executes any functions called on the objects in parallel | 8 interface, and executes any functions called on the objects in parallel |
9 in ReraiserThreads. | 9 in ReraiserThreads. |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 DoesSomethingWithFoo(Parallelizer(list_of_foos)) | 48 DoesSomethingWithFoo(Parallelizer(list_of_foos)) |
49 | 49 |
50 Note that this class spins up a thread for each object. Using this class | 50 Note that this class spins up a thread for each object. Using this class |
51 to parallelize operations that are already fast will incur a net performance | 51 to parallelize operations that are already fast will incur a net performance |
52 penalty. | 52 penalty. |
53 | 53 |
54 """ | 54 """ |
55 # pylint: disable=protected-access | 55 # pylint: disable=protected-access |
56 | 56 |
57 from pylib.utils import reraiser_thread | 57 from devil.utils import reraiser_thread |
58 from pylib.utils import watchdog_timer | 58 from devil.utils import watchdog_timer |
59 | 59 |
60 _DEFAULT_TIMEOUT = 30 | 60 _DEFAULT_TIMEOUT = 30 |
61 _DEFAULT_RETRIES = 3 | 61 _DEFAULT_RETRIES = 3 |
62 | 62 |
63 | 63 |
64 class Parallelizer(object): | 64 class Parallelizer(object): |
65 """Allows parallel execution of method calls across a group of objects.""" | 65 """Allows parallel execution of method calls across a group of objects.""" |
66 | 66 |
67 def __init__(self, objs): | 67 def __init__(self, objs): |
68 assert (objs is not None and len(objs) > 0), ( | 68 assert (objs is not None and len(objs) > 0), ( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 args: The positional args to pass to f. | 233 args: The positional args to pass to f. |
234 kwargs: The keyword args to pass to f. | 234 kwargs: The keyword args to pass to f. |
235 Returns: | 235 Returns: |
236 A Parallelizer wrapping the ReraiserThreadGroup running the map in | 236 A Parallelizer wrapping the ReraiserThreadGroup running the map in |
237 parallel. | 237 parallel. |
238 """ | 238 """ |
239 r = super(SyncParallelizer, self).pMap(f, *args, **kwargs) | 239 r = super(SyncParallelizer, self).pMap(f, *args, **kwargs) |
240 r.pFinish(None) | 240 r.pFinish(None) |
241 return r | 241 return r |
242 | 242 |
OLD | NEW |