本文整理汇总了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)
示例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))
示例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)
示例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
示例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
示例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)
示例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))
示例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")
示例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
示例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)
示例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)
示例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)
示例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
示例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)
示例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)))