diff options
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.py | 45 |
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)) |