Use the ability to save the exception traceback with newer futures

This helps make things much nicer on py2.x release of python.
This commit is contained in:
Joshua Harlow
2015-05-13 17:03:24 -07:00
parent 1d0c33e0a6
commit ed2395ee6c
2 changed files with 12 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
# under the License.
import functools
import sys
import threading
from concurrent import futures as _futures
@@ -23,6 +24,7 @@ from concurrent.futures import thread as _thread
from oslo_utils import importutils
from oslo_utils import reflection
from oslo_utils import timeutils
import six
greenpatcher = importutils.try_import('eventlet.patcher')
greenpool = importutils.try_import('eventlet.greenpool')
@@ -174,8 +176,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

@@ -33,7 +33,7 @@ setup(
license="ASL 2.0",
install_requires=[
# Only needed on 2.6 and 2.7 (can be killed/removed on 3.2+)
'futures',
'futures>=3.0',
'six',
'oslo.utils',
],