From ed2395ee6cacc964fe47ae8c7eb4668b80ded4c0 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 13 May 2015 17:03:24 -0700 Subject: [PATCH] Use the ability to save the exception traceback with newer futures This helps make things much nicer on py2.x release of python. --- futurist/futures.py | 13 +++++++++++-- setup.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/futurist/futures.py b/futurist/futures.py index 0e1f9a7..26824ee 100644 --- a/futurist/futures.py +++ b/futurist/futures.py @@ -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) diff --git a/setup.py b/setup.py index 0e53987..8a0fa88 100755 --- a/setup.py +++ b/setup.py @@ -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', ],