Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: devil/devil/utils/parallelizer.py

Issue 2923443002: [devil] Add system app replacement wrapper script. (Closed)
Patch Set: docstrings for device_temp_file Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « devil/devil/devil_dependencies.json ('k') | devil/devil/utils/parallelizer_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: devil/devil/utils/parallelizer.py
diff --git a/devil/devil/utils/parallelizer.py b/devil/devil/utils/parallelizer.py
index 35995251c879b130e32f034f0238d4335315c3c6..678066c75077b982ca5ef854c8583188faae2b51 100644
--- a/devil/devil/utils/parallelizer.py
+++ b/devil/devil/utils/parallelizer.py
@@ -118,7 +118,7 @@ class Parallelizer(object):
o, args=args, kwargs=kwargs,
name='%s.%s' % (str(d), o.__name__))
for d, o in zip(self._orig_objs, self._objs)])
- r._objs.StartAll() # pylint: disable=W0212
+ r._objs.StartAll()
return r
def pFinish(self, timeout):
@@ -174,7 +174,7 @@ class Parallelizer(object):
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
+ r._objs.StartAll()
return r
def _assertNoShadow(self, attr_name):
@@ -200,6 +200,33 @@ class Parallelizer(object):
class SyncParallelizer(Parallelizer):
"""A Parallelizer that blocks on function calls."""
+ def __enter__(self):
+ """Emulate entering the context of |self|.
+
+ Note that this call is synchronous.
+
+ Returns:
+ A Parallelizer emulating the value returned from entering into the
+ context of |self|.
+ """
+ r = type(self)(self._orig_objs)
+ r._objs = [o.__enter__ for o in r._objs]
+ return r.__call__()
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Emulate exiting the context of |self|.
+
+ Note that this call is synchronous.
+
+ Args:
+ exc_type: the exception type.
+ exc_val: the exception value.
+ exc_tb: the exception traceback.
+ """
+ r = type(self)(self._orig_objs)
+ r._objs = [o.__exit__ for o in r._objs]
+ r.__call__(exc_type, exc_val, exc_tb)
+
# override
def __call__(self, *args, **kwargs):
"""Emulate calling |self| with |args| and |kwargs|.
« no previous file with comments | « devil/devil/devil_dependencies.json ('k') | devil/devil/utils/parallelizer_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698