aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2017-01-18 18:49:07 -0800
committerGravatar Yuchen Zeng <zyc@google.com>2017-01-18 18:49:07 -0800
commit04ec4701e303b8b41d90d5ce6861689c7f0fab7f (patch)
treeb37a55fead11bb07956718671aa1b1ed1bbb3991 /src/python/grpcio_tests/tests/unit/_cython/test_utilities.py
parentb0023d25dc783ba77164c03a39bb7dcc7e446fe8 (diff)
parent6da1dc87aa3384594e9ab6218b1e0886573108de (diff)
Merge remote-tracking branch 'upstream/master' into cares_buildin
Diffstat (limited to 'src/python/grpcio_tests/tests/unit/_cython/test_utilities.py')
-rw-r--r--src/python/grpcio_tests/tests/unit/_cython/test_utilities.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py b/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py
index 6280ce74c4..dffb3733b6 100644
--- a/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py
+++ b/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py
@@ -33,34 +33,35 @@ from grpc._cython import cygrpc
class SimpleFuture(object):
- """A simple future mechanism."""
+ """A simple future mechanism."""
- def __init__(self, function, *args, **kwargs):
- def wrapped_function():
- try:
- self._result = function(*args, **kwargs)
- except Exception as error:
- self._error = error
- self._result = None
- self._error = None
- self._thread = threading.Thread(target=wrapped_function)
- self._thread.start()
+ def __init__(self, function, *args, **kwargs):
- def result(self):
- """The resulting value of this future.
+ def wrapped_function():
+ try:
+ self._result = function(*args, **kwargs)
+ except Exception as error:
+ self._error = error
+
+ self._result = None
+ self._error = None
+ self._thread = threading.Thread(target=wrapped_function)
+ self._thread.start()
+
+ def result(self):
+ """The resulting value of this future.
Re-raises any exceptions.
"""
- self._thread.join()
- if self._error:
- # TODO(atash): re-raise exceptions in a way that preserves tracebacks
- raise self._error
- return self._result
+ self._thread.join()
+ if self._error:
+ # TODO(atash): re-raise exceptions in a way that preserves tracebacks
+ raise self._error
+ return self._result
class CompletionQueuePollFuture(SimpleFuture):
- def __init__(self, completion_queue, deadline):
- super(CompletionQueuePollFuture, self).__init__(
- lambda: completion_queue.poll(deadline))
-
+ def __init__(self, completion_queue, deadline):
+ super(CompletionQueuePollFuture,
+ self).__init__(lambda: completion_queue.poll(deadline))