def get_real_last_traceback(exception):
    """ An unfortunate evil... All because Python's traceback cannot
    determine where my executed code is coming from...
    """
    traceback_blocks = []
    _n, _n, exc_traceback = sys.exc_info()
    tb_list = get_all_tracebacks(exc_traceback)[1:]

    # Remove already captured tracebacks
    # TODO(jmv): This must be a better way of doing this. Need to revisit.
    tb_list = [tb for tb in tb_list if tb not in CAPTURED_TRACEBACKS]
    CAPTURED_TRACEBACKS.extend(tb_list)

    for traceback in tb_list:
        lines, path, line_num = get_source_from_frame(traceback.tb_frame)
        traceback_lines = get_numbered_source(lines, traceback.tb_lineno,
                                              line_num)

        traceback_lines.insert(0, '  - {0}'.format(path))
        traceback_lines.insert(1, '  ------------------')
        traceback_lines.append('  ------------------')
        traceback_blocks.append(traceback_lines)

    traced_lines = ['Error Traceback:']
    traced_lines.extend(itertools.chain.from_iterable(traceback_blocks))
    traced_lines.append('  - Error | {0}: {1}'.format(
        type(exception).__name__, exception))

    return traced_lines
def get_real_last_traceback ( exception ) : traceback_blocks = [ ] _n , _n , exc_traceback = sys . exc_info ( ) tb_list = get_all_tracebacks ( exc_traceback ) [ 1 : ] tb_list = [ tb for tb in tb_list if tb not in CAPTURED_TRACEBACKS ] CAPTURED_TRACEBACKS . extend ( tb_list ) for traceback in tb_list : lines , path , line_num = get_source_from_frame ( traceback . tb_frame ) traceback_lines = get_numbered_source ( lines , traceback . tb_lineno , line_num ) traceback_lines . insert ( 0 , '  - {0}' . format ( path ) ) traceback_lines . insert ( 1 , '  ------------------' ) traceback_lines . append ( '  ------------------' ) traceback_blocks . append ( traceback_lines ) traced_lines = [ 'Error Traceback:' ] traced_lines . extend ( itertools . chain . from_iterable ( traceback_blocks ) ) traced_lines . append ( '  - Error | {0}: {1}' . format ( type ( exception ) . __name__ , exception ) ) return traced_lines
An unfortunate evil... All because Python's traceback cannot
    determine where my executed code is coming from...