当前位置: 首页>>代码示例>>Python>>正文


Python traceback.format_list方法代码示例

本文整理汇总了Python中traceback.format_list方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.format_list方法的具体用法?Python traceback.format_list怎么用?Python traceback.format_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traceback的用法示例。


在下文中一共展示了traceback.format_list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trace

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def trace(type, **kwargs):
    assert not TRACE_RESERVED_KEYS.intersection(
        kwargs.keys()
    ), ".trace() keyword parameters cannot include {}".format(TRACE_RESERVED_KEYS)
    task_id = get_task_id()
    if task_id is None:
        yield
        return
    tracer = tracers.get(task_id)
    if tracer is None:
        yield
        return
    start = time.time()
    yield
    end = time.time()
    trace_info = {
        "type": type,
        "start": start,
        "end": end,
        "duration_ms": (end - start) * 1000,
        "traceback": traceback.format_list(traceback.extract_stack(limit=6)[:-3]),
    }
    trace_info.update(kwargs)
    tracer.append(trace_info) 
开发者ID:simonw,项目名称:datasette,代码行数:26,代码来源:tracer.py

示例2: extra_serializer

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def extra_serializer(obj: Any) -> Union[int, str, List[Any], Dict[str, Any]]:
    """JSON serializer for objects not serializable by default json code"""

    if isinstance(obj, datetime.datetime):
        return dtutil.dt2ts(obj)
    if isinstance(obj, bytes):
        return obj.decode('utf-8')
    if isinstance(obj, decimal.Decimal):
        return obj.to_eng_string()
    if isinstance(obj, (set, KeysView)):
        return list(obj)
    if isinstance(obj, Exception):
        stack = traceback.extract_tb(obj.__traceback__)
        return traceback.format_list(stack)
    if hasattr(obj, 'to_dict'):
        return obj.to_dict()
    if hasattr(obj, '__attrs_attrs__'):
        val: Dict[str, Any] = {}
        for a in obj.__attrs_attrs__:
            val[a.name] = getattr(obj, a.name)
        return val
    raise TypeError('Type {t} not serializable - {obj}'.format(t=type(obj), obj=obj)) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:24,代码来源:serialization.py

示例3: showtraceback

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def showtraceback(self):
        """Display the exception that just occurred.

        We remove the first stack item because it is our own code.

        The output is written by self.write(), below.

        """
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(type, value)
        finally:
            tblist = tb = None
        map(self.write, list) 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:code.py

示例4: format_exc

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def format_exc(self, limit=None):
        """
        This is like exception.print_exc(limit) but returns a string instead
        of printing to a file.
        """
        result = ["Traceback (most recent call last):\n"]

        tb_list = self._traceback

        if limit is not None:
            tb_list = tb_list[-limit:]

        result.extend(traceback.format_list(tb_list))

        if self.cause is not None:
            result.extend(traceback.format_exception_only(self.cause.__class__,
                                                          self.cause))
            return result
        else:
            return result 
开发者ID:boto,项目名称:botoflow,代码行数:22,代码来源:exceptions.py

示例5: format_exc

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def format_exc(limit=None, exception=None, tb_list=None):
    """
    This is like print_exc(limit) but returns a string instead of printing to a
    file.
    """
    result = ["Traceback (most recent call last):\n"]
    if exception is None:
        exception = get_context_with_traceback(get_async_context()).exception

    if tb_list is None:
        tb_list = extract_tb(limit)

    if tb_list:
        result.extend(traceback.format_list(tb_list))
        result.extend(traceback.format_exception_only(exception.__class__,
                                                      exception))
        return result
    else:
        return None 
开发者ID:boto,项目名称:botoflow,代码行数:21,代码来源:async_traceback.py

示例6: showtraceback

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def showtraceback(self, *args, **kwargs):
        """Display the exception that just occurred.

        We remove the first stack item because it is our own code.

        The output is written by self.write(), below.

        """
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(type, value)
        finally:
            tblist = tb = None
        map(self.write, list) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:24,代码来源:pydevconsole_code_for_ironpython.py

示例7: showtraceback

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def showtraceback(self, *args, **kwargs):
        """Display the exception that just occurred."""
        # Override for avoid using sys.excepthook PY-12600
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            lines = traceback.format_list(tblist)
            if lines:
                lines.insert(0, "Traceback (most recent call last):\n")
            lines.extend(traceback.format_exception_only(type, value))
        finally:
            tblist = tb = None
        sys.stderr.write(''.join(lines)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:19,代码来源:pydevconsole.py

示例8: print_small_exception

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def print_small_exception(start_after):
    type, value, traceback_ = sys.exc_info()

    tb = traceback.extract_tb(traceback_)
    index = 0

    for i, trace in enumerate(tb):
        if trace[2] == start_after:
            index = i + 1
            break

    lines = traceback.format_list(tb[index:])
    lines += traceback.format_exception_only(type, value)

    for line in lines:
        sys.stderr.write(line)

    sys.stderr.write("\n") 
开发者ID:streamlink,项目名称:streamlink,代码行数:20,代码来源:session.py

示例9: _reraise_with_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def _reraise_with_stack(func, e):
    if func.stack is not None:
        # Reraise any type of exceptions including the following:
        # - Chainer raises RuntimeError for NaN values; and
        # - NumPy raises FloatingPointError for invalid values.

        # TODO(kataoka): unify variable._check_grad_type and below
        additional_message = \
            '\n{}\nStacktrace of the function is below:\n{}'.format(
                '-' * _get_columns(),
                ''.join(traceback.format_list(func.stack[:-1])))
        if e.args:
            e.args = (e.args[0] + additional_message,) + e.args[1:]
        else:
            e.args = (additional_message,)
    raise 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:_backprop_utils.py

示例10: _raise_grad_error

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def _raise_grad_error(exc_type, func, msg):
    detail = ''
    if func:
        detail = 'Function `{0}` ({1}) has a bug.\n'.format(
            type(func)._impl_name, func.label)
        stack = func.stack
        if stack:
            detail += 'Stacktrace of the function is below:\n'
            for line in traceback.format_list(func.stack):
                detail += line
        detail += '''
Please report this error to the issue tracker with the stack trace,
the information of your environment, and your script:
https://github.com/chainer/chainer/issues/new.
'''

    raise exc_type(detail + msg) 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:variable.py

示例11: error_to_janus_msg

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def error_to_janus_msg(session_id=0, transaction=None, exception=None):
    """ convert a Error exception to a message in dict form """
    error = {}
    if isinstance(exception, JanusCloudError):
        error["code"] = exception.code
        error["reason"] = str(exception)
    elif isinstance(exception, SchemaError):
        error["code"] = JANUS_ERROR_INVALID_ELEMENT_TYPE
        error["reason"] = str(exception)
    else:
        error["code"] = 500
        error["reason"] = str(exception)

    type, dummy, tb = sys.exc_info()
    tb_list = traceback.format_list(traceback.extract_tb(tb)[-10:])
    error["traceback"] = tb_list
    return create_janus_msg("error", session_id, transaction, error=error) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:19,代码来源:utils.py

示例12: print_exception

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def print_exception(exc_type, exc_value, exc_tb):
    # remove debugger frames from the top and bottom of the traceback
    tb = traceback.extract_tb(exc_tb)
    for i in [0, -1]:
        while tb:
            frame_file = path.normcase(tb[i][0])
            if not any(is_same_py_file(frame_file, f) for f in DONT_DEBUG):
                break
            del tb[i]

    # print the traceback
    if tb:
        print('Traceback (most recent call last):')
        for out in traceback.format_list(tb):
            sys.stderr.write(out)
    
    # print the exception
    for out in traceback.format_exception_only(exc_type, exc_value):
        sys.stdout.write(out) 
开发者ID:ms-iot,项目名称:iot-utilities,代码行数:21,代码来源:visualstudio_py_debugger.py

示例13: _format_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def _format_stack(task, coro, complete=False):
    '''
    Formats a traceback from a stack of coroutines/generators
    '''
    dirname = os.path.dirname(__file__)
    extracted_list = []
    checked = set()
    for f in _get_stack(coro):
        lineno = f.f_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        if not complete and os.path.dirname(filename) == dirname:
            continue
        if filename not in checked:
            checked.add(filename)
            linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        extracted_list.append((filename, lineno, name, line))
    if not extracted_list:
        resp = 'No stack for %r' % task
    else:
        resp = 'Stack for %r (most recent call last):\n' % task
        resp += ''.join(traceback.format_list(extracted_list))
    return resp 
开发者ID:anyant,项目名称:rssant,代码行数:27,代码来源:asyncio_tools.py

示例14: kill

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def kill(self, reason):
        log.debug("GameModel.kill: players=%s, self.ply=%s: Killing a game for reason %d\n%s" % (
                  repr(self.players), str(self.ply), reason, "".join(
                      traceback.format_list(traceback.extract_stack())).strip()))

        self.status = KILLED
        self.reason = reason

        for player in self.players:
            player.end(self.status, reason)

        for spectator in self.spectators.values():
            spectator.end(self.status, reason)

        if self.timed:
            self.timemodel.end()

        self.emit("game_ended", reason) 
开发者ID:pychess,项目名称:pychess,代码行数:20,代码来源:GameModel.py

示例15: _render_traceback

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_list [as 别名]
def _render_traceback(self, io, tb):  # type: (IO, ...) -> None
        frames = []
        while tb:
            frames.append(self._format_traceback_frame(io, tb))

            tb = tb.tb_next

        io.write_line("<b>Traceback (most recent call last):</b>")
        io.write_line("".join(traceback.format_list(frames))) 
开发者ID:sdispater,项目名称:clikit,代码行数:11,代码来源:exception_trace.py


注:本文中的traceback.format_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。