diff --git a/taskflow/tests/unit/test_utils_async_utils.py b/taskflow/tests/unit/test_utils_async_utils.py index b538c2ee..642be96e 100644 --- a/taskflow/tests/unit/test_utils_async_utils.py +++ b/taskflow/tests/unit/test_utils_async_utils.py @@ -74,13 +74,6 @@ class MakeCompletedFutureTest(test.TestCase): self.assertTrue(future.done()) self.assertIs(future.result(), result) - def test_make_completed_future_exception(self): - result = IOError("broken") - future = au.make_completed_future(result, exception=True) - self.assertTrue(future.done()) - self.assertRaises(IOError, future.result) - self.assertIsNotNone(future.exception()) - class AsyncUtilsSynchronousTest(test.TestCase, WaitForAnyTestsMixin): diff --git a/taskflow/types/futures.py b/taskflow/types/futures.py index 2a6f7b6f..f14e4015 100644 --- a/taskflow/types/futures.py +++ b/taskflow/types/futures.py @@ -15,6 +15,7 @@ # under the License. import functools +import sys import threading from concurrent import futures as _futures @@ -22,6 +23,7 @@ from concurrent.futures import process as _process from concurrent.futures import thread as _thread from oslo_utils import importutils from oslo_utils import reflection +import six greenpatcher = importutils.try_import('eventlet.patcher') greenpool = importutils.try_import('eventlet.greenpool') @@ -175,8 +177,15 @@ class _WorkItem(object): return try: result = self.fn(*self.args, **self.kwargs) - except BaseException as e: - self.future.set_exception(e) + except BaseException: + exc_type, exc_value, exc_tb = sys.exc_info() + try: + if six.PY2: + self.future.set_exception_info(exc_value, exc_tb) + else: + self.future.set_exception(exc_value) + finally: + del(exc_type, exc_value, exc_tb) else: self.future.set_result(result) diff --git a/taskflow/utils/async_utils.py b/taskflow/utils/async_utils.py index e04c44e7..aec62abf 100644 --- a/taskflow/utils/async_utils.py +++ b/taskflow/utils/async_utils.py @@ -30,13 +30,10 @@ _DONE_STATES = frozenset([ ]) -def make_completed_future(result, exception=False): - """Make a future completed with a given result.""" +def make_completed_future(result): + """Make and return a future completed with a given result.""" future = futures.Future() - if exception: - future.set_exception(result) - else: - future.set_result(result) + future.set_result(result) return future