Merge "Use newer versions of futures that adds exception tracebacks"

This commit is contained in:
Jenkins
2015-05-30 03:07:51 +00:00
committed by Gerrit Code Review
3 changed files with 14 additions and 15 deletions

View File

@@ -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):

View File

@@ -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')
@@ -185,8 +187,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)

View File

@@ -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