Chromium Code Reviews| Index: build/android/pylib/utils/parallelizer.py |
| diff --git a/build/android/pylib/utils/parallelizer.py b/build/android/pylib/utils/parallelizer.py |
| index 761455223ceee6ddf1466d5ec3363b97b1fb814f..e312064b058f7df8b1660b76942ae319c32d1ca9 100644 |
| --- a/build/android/pylib/utils/parallelizer.py |
| +++ b/build/android/pylib/utils/parallelizer.py |
| @@ -155,6 +155,35 @@ class Parallelizer(object): |
| self.pFinish(timeout) |
| return self._objs |
| + def pMap(self, f, *args, **kwargs): |
| + """Map a function across the current wrapped objects in parallel. |
| + |
| + This calls f(o, *args, **kwargs) for each o in the set of wrapped objects. |
| + |
| + Note that this call is asynchronous. Call pFinish on the return value to |
| + block until the call finishes. |
| + |
| + Args: |
| + f: The function to call. |
| + args: The positional args to pass to f. |
| + kwargs: The keyword args to pass to f. |
| + Returns: |
| + A Parallelizer wrapping the ReraiserThreadGroup running the map in |
| + parallel. |
| + """ |
| + self._assertNoShadow('pMap') |
| + r = type(self)(self._orig_objs) |
| + for d, o in zip(self._orig_objs, self._objs): |
| + # TODO(jbudorick): XXX REMOVE BEFORE COMMITTING |
|
jbudorick
2014/08/15 17:41:47
This will be gone in the next patchset, fwiw.
|
| + print '%s(%s)' % (f.__name__, d) |
| + r._objs = reraiser_thread.ReraiserThreadGroup( |
| + [reraiser_thread.ReraiserThread( |
| + f, args=tuple([o] + list(args)), kwargs=kwargs, |
| + name='%s(%s)' % (f.__name__, d)) |
| + for d, o in zip(self._orig_objs, self._objs)]) |
| + r._objs.StartAll() # pylint: disable=W0212 |
| + return r |
| + |
| def _assertNoShadow(self, attr_name): |
| """Ensures that |attr_name| isn't shadowing part of the wrapped obejcts. |
| @@ -194,3 +223,23 @@ class SyncParallelizer(Parallelizer): |
| r.pFinish(None) |
| return r |
| + #override |
| + def pMap(self, f, *args, **kwargs): |
| + """Map a function across the current wrapped objects in parallel. |
| + |
| + This calls f(o, *args, **kwargs) for each o in the set of wrapped objects. |
| + |
| + Note that this call is synchronous. |
| + |
| + Args: |
| + f: The function to call. |
| + args: The positional args to pass to f. |
| + kwargs: The keyword args to pass to f. |
| + Returns: |
| + A Parallelizer wrapping the ReraiserThreadGroup running the map in |
| + parallel. |
| + """ |
| + r = super(SyncParallelizer, self).pMap(f, *args, **kwargs) |
| + r.pFinish(None) |
| + return r |
| + |