async_gui icon indicating copy to clipboard operation
async_gui copied to clipboard

When an exception occurs in a future, we lose most of the traceback

Open ctoth opened this issue 11 years ago • 0 comments

Consider the following:


def bad():
    worse()

def worse():
    raise RuntimeError("Bad Day")

Currently, if this code gets executed in a Task, we'll lose the traceback, only the last line will show up. When I ran across this problem with Python Futures in my own code, I came up with a janky solution with a subclassed Executor class, perhaps you can think of something better than this for async_gui, which is awesome btw, thank you.

class CustomExecutor(concurrent.futures.thread.ThreadPoolExecutor):

    def submit(self, task, *args, **kwargs):
        @functools.wraps(task)
        def task_wrapper():
            try:
                return task(*args, **kwargs)
            except Exception as e:
                logger.exception("Error executing %r with args %r and kwargs %r" % (task, args, kwargs))
                raise
        future = super(CustomExecutor, self).submit(task_wrapper)
        return future

ctoth avatar Jul 15 '14 20:07 ctoth