Skip to content

Commit

Permalink
Print the exception origin by fake futures
Browse files Browse the repository at this point in the history
Fixes #208
  • Loading branch information
tfarago committed Feb 25, 2014
1 parent 7683adc commit b2f14c3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions concert/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""
import functools
import traceback
import concert.config
from concurrent.futures import ThreadPoolExecutor, Future

Expand All @@ -23,6 +24,14 @@
import queue


# Provide nicely formatted exceptions if possible
_colored_exceptions = True
try:
from IPython.core.ultratb import AutoFormattedTB
except ImportError:
_colored_exceptions = False


# Patch futures so that they provide a join() and kill() method
def _join(self, _timeout=None):
self.result()
Expand Down Expand Up @@ -52,6 +61,10 @@ def _inner(*args, **kwargs):
result = func(*args, **kwargs)
future.set_result(result)
except Exception as e:
if _colored_exceptions:
AutoFormattedTB(mode='Verbose')()
else:
traceback.print_exc()
future.set_exception(e)

return future
Expand Down

0 comments on commit b2f14c3

Please sign in to comment.