本文整理汇总了Python中traceback.print_list函数的典型用法代码示例。如果您正苦于以下问题:Python print_list函数的具体用法?Python print_list怎么用?Python print_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_stack
def print_stack(self, *, limit=None, file=None):
"""Print the stack or traceback for this task's coroutine.
This produces output similar to that of the traceback module,
for the frames retrieved by get_stack(). The limit argument
is passed to get_stack(). The file argument is an I/O stream
to which the output is written; by default output is written
to sys.stderr.
"""
extracted_list = []
checked = set()
for f in self.get_stack(limit=limit):
lineno = f.f_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
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))
exc = self._exception
if not extracted_list:
print('No stack for %r' % self, file=file)
elif exc is not None:
print('Traceback for %r (most recent call last):' % self,
file=file)
else:
print('Stack for %r (most recent call last):' % self,
file=file)
traceback.print_list(extracted_list, file=file)
if exc is not None:
for line in traceback.format_exception_only(exc.__class__, exc):
print(line, file=file, end='')
示例2: handler
def handler(signum, frame):
limit = None
file = None
traceback.print_list(traceback.extract_stack(frame, limit=limit), file=file)
print(signum, frame)
print(dir(frame))
sys.exit(-1)
示例3: __call__
def __call__(self, *args):
assert len(args) == len(self.input_types), "Wrong number of inputs provided"
self.args = tuple(core.as_valid_array(arg, intype) for (arg, intype) in zip(args, self.input_types))
for instr in self.eg.instrs:
if profiler.on: tstart = time.time()
try:
instr.fire(self)
except Exception as e:
traceback.print_exc()
if isinstance(instr, (ReturnByRef,ReturnByVal)):
if core.get_config()["debug"]:
assert "stack" in instr.node_props
utils.colorprint(utils.Color.MAGENTA, "HERE'S THE STACK WHEN THE OFFENDING NODE WAS CREATED\n",o=sys.stderr)
print>>sys.stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>"
traceback.print_list(instr.node_props["stack"])
print>>sys.stderr, "<<<<<<<<<<<<<<<<<<<<<<<<<<"
raise e
else:
utils.error("Didn't save the stack so I can't give you a nice traceback :(. Try running with CGT_FLAGS=debug=True")
raise e
else:
utils.error("Oy vey, an exception occurred in a %s Instruction. I don't know how to help you debug this one right now :(."%type(instr))
raise e
if profiler.on: profiler.update(instr, time.time()-tstart)
outputs = [self.get(loc) for loc in self.output_locs]
if self.copy_outputs: outputs = map(_copy, outputs)
return outputs
示例4: _task_print_stack
def _task_print_stack(task, limit, file):
extracted_list = []
checked = set()
for f in task.get_stack(limit=limit):
lineno = f.f_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
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))
exc = task._exception
if not extracted_list:
print('No stack for {!r}'.format(task), file=file)
elif exc is not None:
print('Traceback for {!r} (most recent call last):'.format(task), file=file)
else:
print('Stack for {!r} (most recent call last):'.format(task), file=file)
traceback.print_list(extracted_list, file=file)
if exc is not None:
for line in traceback.format_exception_only(exc.__class__, exc):
print(line, file=file, end='')
示例5: stacktrace
def stacktrace():
buf = cStringIO.StringIO()
stack = traceback.extract_stack()
traceback.print_list(stack[:-2], file=buf)
stacktrace_string = buf.getvalue()
buf.close()
return stacktrace_string
示例6: new_test
def new_test():
p = PssAnalyzer()
folder = os.path.join(os.getcwd(),"run_files")
folder = os.path.join(folder,"uniqes")
p.appent_pattern(folder, ".*best.*")
r = p.solved_percent_ext()
print_list(r)
示例7: dump
def dump(cls, label):
df = cls.dump_file or sys.stderr
s = StringIO()
print >>s, "\nDumping thread %s:" % (label, )
try:
raise ZeroDivisionError
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back.f_back
traceback.print_list(traceback.extract_stack(f, None), s)
df.write(s.getvalue())
示例8: test_print_list
def test_print_list():
expected_string = u""" vi +21 traceback/tests.py # _triple
one()
vi +11 traceback/tests.py # one
two()
vi +10 traceback/tests.py # two
h[1]
"""
out = StringIO()
print_list(extract_tb(_tb()), file=out)
eq_(out.getvalue(), expected_string)
示例9: test_unsolved
def test_unsolved():
p = PssAnalyzer()
folder = os.path.join(os.getcwd(),"run_files")
folder = os.path.join(folder,"uniqes")
p.appent_pattern(folder, ".*beam.*")
#p = p.select("AnytimeBest-d250_with_PowerHeuristic2")
#p = p.select("AnytimeBeam-w20-.*")
print "unsolved_rooms"
unsolved_rooms = p.get_unsolved_rooms(roomset="heavy_roomset")
print_list(unsolved_rooms)
示例10: __init__
def __init__(self, *args, **kwargs):
if kwargs:
# The call to list is needed for Python 3
assert list(kwargs.keys()) == ["variable"]
tr = getattr(list(kwargs.values())[0].tag, "trace", [])
if type(tr) is list and len(tr) > 0:
sio = StringIO()
print("\nBacktrace when the variable is created:", file=sio)
for subtr in list(kwargs.values())[0].tag.trace:
traceback.print_list(subtr, sio)
args = args + (str(sio.getvalue()),)
s = "\n".join(args) # Needed to have the new line print correctly
Exception.__init__(self, s)
示例11: t
def t():
p = PssAnalyzer()
p.load_bstf()
r = p.solved_percent()
name,_ = do_by_key(max,r,1)
pss = p.select_first(name,'.*stat.*')
print pss.roomset.name
print pss.name
print pss.solutions
t = p.room_id_with_runtime_table(pss)
print_list( do_by_key(sorted,t,1) )
return r
示例12: test_solution_improvment
def test_solution_improvment():
p = PssAnalyzer()
folder = os.path.join(os.getcwd(),"run_files")
folder = os.path.join(folder,"uniqes")
p.appent_pattern(folder, ".*")
#p.appent_pattern(folder, ".*limit.*")
#p = p.select("AnytimeBest-d250_with_PowerHeuristic2")
#p = p.select(".*", roomset_pattern="heavy_roomset")
l = p.solution_imp()
print_list(l)
print len(l), "from", p.rooms_count()
示例13: error
def error(key, include_traceback=False):
exc_type, exc_value, _ = sys.exc_info()
msg = StringIO()
if include_traceback:
frame = inspect.trace()[-1]
filename = frame[1]
lineno = frame[2]
funcname = frame[3]
code = ''.join(frame[4])
traceback.print_list([(filename, lineno, funcname, code)], file=msg)
if exc_type:
msg.write(''.join(traceback.format_exception_only(exc_type, exc_value)))
errors[key] = msg.getvalue()
sys.exc_clear()
示例14: print_exception
def print_exception():
flush_stdout()
efile = sys.stderr
typ, val, tb = excinfo = sys.exc_info()
sys.last_type, sys.last_value, sys.last_traceback = excinfo
tbe = traceback.extract_tb(tb)
print>>efile, '\nTraceback (most recent call last):'
exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
print>>efile, line,
示例15: get_variable_trace_string
def get_variable_trace_string(v):
sio = StringIO()
# For backward compatibility with old trace
tr = getattr(v.tag, 'trace', [])
if isinstance(tr, list) and len(tr) > 0:
print(" \nBacktrace when that variable is created:\n", file=sio)
# The isinstance is needed to handle old pickled trace
if isinstance(tr[0], tuple):
traceback.print_list(v.tag.trace, sio)
else:
# Print separate message for each element in the list of
# batcktraces
for subtr in tr:
traceback.print_list(subtr, sio)
return sio.getvalue()