From 260201c8b710a06af0bcfcd5631846440794adcd Mon Sep 17 00:00:00 2001 From: Andrew Lazarev Date: Wed, 17 Jun 2015 16:42:31 -0700 Subject: [PATCH] Added failed thread group stacktrace to logs Stacktrace will be printed as text, but this is better than having no stacktrace. Change-Id: Icbf1affe857a34b65efb76f282573d234b5c68f9 Closes-Bug: #1465398 --- sahara/context.py | 7 ++++++- sahara/exceptions.py | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sahara/context.py b/sahara/context.py index be7ec4dc..d5b96e6c 100644 --- a/sahara/context.py +++ b/sahara/context.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import traceback + import eventlet from eventlet.green import threading from eventlet.green import time @@ -199,6 +201,7 @@ def _wrapper(ctx, thread_description, thread_group, func, *args, **kwargs): thread=thread_description, exception=e)) if thread_group and not thread_group.exc: thread_group.exc = e + thread_group.exc_stacktrace = traceback.format_exc() thread_group.failed_thread = thread_description finally: if thread_group: @@ -224,6 +227,7 @@ class ThreadGroup(object): def __init__(self, thread_pool_size=1000): self.tg = greenpool.GreenPool(size=thread_pool_size) self.exc = None + self.exc_stacktrace = None self.failed_thread = None self.threads = 0 self.cv = threading.Condition() @@ -256,7 +260,8 @@ class ThreadGroup(object): self.cv.wait() if self.exc: - raise ex.ThreadException(self.failed_thread, self.exc) + raise ex.ThreadException(self.failed_thread, self.exc, + self.exc_stacktrace) def __enter__(self): return self diff --git a/sahara/exceptions.py b/sahara/exceptions.py index b5ccaac5..575d7acb 100644 --- a/sahara/exceptions.py +++ b/sahara/exceptions.py @@ -193,12 +193,14 @@ class DataTooBigException(SaharaException): class ThreadException(SaharaException): code = "THREAD_EXCEPTION" - message_template = _("An error occurred in thread '%(thread)s': %(e)s") + message_template = _("An error occurred in thread '%(thread)s': %(e)s" + "\n%(stacktrace)s") - def __init__(self, thread_description, e): + def __init__(self, thread_description, e, stacktrace): formatted_message = self.message_template % { 'thread': thread_description, - 'e': six.text_type(e)} + 'e': six.text_type(e), + 'stacktrace': stacktrace} super(ThreadException, self).__init__(formatted_message)