本文整理汇总了Python中sys.last_traceback方法的典型用法代码示例。如果您正苦于以下问题:Python sys.last_traceback方法的具体用法?Python sys.last_traceback怎么用?Python sys.last_traceback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.last_traceback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_with_api
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def run_with_api(self, code):
"""Run code with didyoumean after enabling didyoumean hook."""
prev_hook = sys.excepthook
self.assertEqual(prev_hook, sys.excepthook)
didyoumean_enablehook()
self.assertNotEqual(prev_hook, sys.excepthook)
try:
no_exception(code)
except:
last_type, last_value, last_traceback = sys.exc_info()
with suppress_stderr():
sys.excepthook(last_type, last_value, last_traceback)
raise
finally:
self.assertNotEqual(prev_hook, sys.excepthook)
didyoumean_disablehook()
self.assertEqual(prev_hook, sys.excepthook)
示例2: showtraceback
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [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)
示例3: post_mortem
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def post_mortem(t=None):
if t is None:
t = sys.exc_info()[2] # Will be valid if we are called from an except handler.
if t is None:
try:
t = sys.last_traceback
except AttributeError:
print "No traceback can be found from which to perform post-mortem debugging!"
print "No debugging can continue"
return
p = _GetCurrentDebugger()
if p.frameShutdown: return # App closing
# No idea why I need to settrace to None - it should have been reset by now?
sys.settrace(None)
p.reset()
while t.tb_next != None: t = t.tb_next
p.bAtPostMortem = 1
p.prep_run(None)
try:
p.interaction(t.tb_frame, t)
finally:
t = None
p.bAtPostMortem = 0
p.done_run()
示例4: verifyStderr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def verifyStderr(self, method, successRe) :
"""
Call method() while capturing sys.stderr output internally and
call self.fail() if successRe.search() does not match the stderr
output. This is used to test for uncatchable exceptions.
"""
stdErr = sys.stderr
sys.stderr = StringIO()
try:
method()
finally:
temp = sys.stderr
sys.stderr = stdErr
errorOut = temp.getvalue()
if not successRe.search(errorOut) :
self.fail("unexpected stderr output:\n"+errorOut)
if sys.version_info < (3, 0) : # XXX: How to do this in Py3k ???
sys.exc_traceback = sys.last_traceback = None
示例5: print_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def print_exception():
import linecache
linecache.checkcache()
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,
示例6: showsyntaxerror
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def showsyntaxerror(self, filename=None):
"""Display the syntax error that just occurred.
This doesn't display a stack trace because there isn't one.
If a filename is given, it is stuffed in the exception instead
of what was there before (because Python's parser always uses
"<string>" when reading from a string).
"""
etype, value, last_traceback = self._get_exc_info()
if filename and issubclass(etype, SyntaxError):
try:
value.filename = filename
except:
# Not the format we expect; leave it alone
pass
stb = self.SyntaxTB.structured_traceback(etype, value, [])
self._showtraceback(etype, value, stb)
# This is overridden in TerminalInteractiveShell to show a message about
# the %paste magic.
示例7: _stack_viewer
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def _stack_viewer(parent):
root = tk.Tk()
root.title("Test StackViewer")
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
root.geometry("+%d+%d"%(x, y + 150))
flist = PyShellFileList(root)
try: # to obtain a traceback object
intentional_name_error
except NameError:
exc_type, exc_value, exc_tb = sys.exc_info()
# inject stack trace to sys
sys.last_type = exc_type
sys.last_value = exc_value
sys.last_traceback = exc_tb
StackBrowser(root, flist=flist, top=root, tb=exc_tb)
# restore sys to original state
del sys.last_type
del sys.last_value
del sys.last_traceback
示例8: showtraceback
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [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)
示例9: showsyntaxerror
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def showsyntaxerror(self, filename=None):
"""Display the syntax error that just occurred."""
# Override for avoid using sys.excepthook PY-12600
type, value, tb = sys.exc_info()
sys.last_type = type
sys.last_value = value
sys.last_traceback = tb
if filename and type is SyntaxError:
# Work hard to stuff the correct filename in the exception
try:
msg, (dummy_filename, lineno, offset, line) = value.args
except ValueError:
# Not the format we expect; leave it alone
pass
else:
# Stuff in the right filename
value = SyntaxError(msg, (filename, lineno, offset, line))
sys.last_value = value
list = traceback.format_exception_only(type, value)
sys.stderr.write(''.join(list))
示例10: showtraceback
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [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))
示例11: pytest_runtest_call
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def pytest_runtest_call(item: Item) -> None:
_update_current_test_var(item, "call")
try:
del sys.last_type
del sys.last_value
del sys.last_traceback
except AttributeError:
pass
try:
item.runtest()
except Exception as e:
# Store trace info to allow postmortem debugging
sys.last_type = type(e)
sys.last_value = e
assert e.__traceback__ is not None
# Skip *this* frame
sys.last_traceback = e.__traceback__.tb_next
raise e
示例12: disconnect
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def disconnect(self):
sock = self.socket
if sock is None:
return
self.socket = None
try:
sock.send(DONE)
except Exception:
pass
try:
sock.shutdown(socket.SHUT_RDWR)
except Exception:
pass
try:
sock.close()
except Exception:
pass
sys.last_traceback = None
示例13: showtraceback
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [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.
"""
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
sys.last_traceback = last_tb
try:
lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
if sys.excepthook is sys.__excepthook__:
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
sys.excepthook(ei[0], ei[1], last_tb)
finally:
last_tb = ei = None
示例14: didyoumean_postmortem
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def didyoumean_postmortem():
"""Post postem function to add suggestions to last exception thrown.
Add suggestions to last exception thrown (in interactive mode) and
return it (which should print it).
"""
if hasattr(sys, 'last_type'):
typ, val, trace = sys.last_type, sys.last_value, sys.last_traceback
add_suggestions_to_exception(typ, val, trace)
return val
return None
示例15: check_sys_last_attr_not_set
# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_traceback [as 别名]
def check_sys_last_attr_not_set(self):
"""Check that attributes 'last_<xxx>' do not exist."""
for a in ('last_type', 'last_value', 'last_traceback'):
self.assertFalse(hasattr(sys, a))