Python sys.last_traceback() Examples
The following are 30
code examples of sys.last_traceback().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: Remote.py From guppy3 with MIT License | 6 votes |
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
Example #2
Source File: StackViewer.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: StackViewer.py From oss-ftp with MIT License | 6 votes |
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
Example #4
Source File: pydevconsole_code_for_ironpython.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
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)
Example #5
Source File: pydevconsole.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
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))
Example #6
Source File: code.py From meddle with MIT License | 6 votes |
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)
Example #7
Source File: code.py From Imogen with MIT License | 6 votes |
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
Example #8
Source File: didyoumean_api_tests.py From DidYouMean-Python with MIT License | 6 votes |
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)
Example #9
Source File: test_compare.py From oss-ftp with MIT License | 6 votes |
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
Example #10
Source File: test_compare.py From oss-ftp with MIT License | 6 votes |
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
Example #11
Source File: run.py From oss-ftp with MIT License | 6 votes |
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,
Example #12
Source File: code.py From oss-ftp with MIT License | 6 votes |
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)
Example #13
Source File: pydevconsole.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
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))
Example #14
Source File: code.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #15
Source File: __init__.py From ironpython2 with Apache License 2.0 | 6 votes |
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()
Example #16
Source File: test_compare.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #17
Source File: test_compare.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #18
Source File: code.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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
Example #19
Source File: code.py From BinderFilter with MIT License | 6 votes |
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)
Example #20
Source File: runner.py From pytest with MIT License | 6 votes |
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
Example #21
Source File: code.py From Computable with MIT License | 6 votes |
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)
Example #22
Source File: interactiveshell.py From Computable with MIT License | 6 votes |
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.
Example #23
Source File: test_compare.py From BinderFilter with MIT License | 6 votes |
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
Example #24
Source File: test_compare.py From BinderFilter with MIT License | 6 votes |
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
Example #25
Source File: run.py From BinderFilter with MIT License | 6 votes |
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,
Example #26
Source File: dis.py From pmatic with GNU General Public License v2.0 | 5 votes |
def distb(tb=None): """Disassemble a traceback (default: last traceback).""" if tb is None: try: tb = sys.last_traceback except AttributeError: raise RuntimeError, "no last traceback to disassemble" while tb.tb_next: tb = tb.tb_next disassemble(tb.tb_frame.f_code, tb.tb_lasti)
Example #27
Source File: disgen.py From coveragepy-bbmirror with Apache License 2.0 | 5 votes |
def distb(tb=None): """Disassemble a traceback (default: last traceback).""" if tb is None: try: tb = sys.last_traceback except AttributeError: raise RuntimeError("no last traceback to disassemble") while tb.tb_next: tb = tb.tb_next return disassemble(tb.tb_frame.f_code, tb.tb_lasti)
Example #28
Source File: traceback.py From pmatic with GNU General Public License v2.0 | 5 votes |
def print_last(limit=None, file=None): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" if not hasattr(sys, "last_type"): raise ValueError("no last exception") if file is None: file = sys.stderr print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)
Example #29
Source File: dis.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def distb(tb=None, *, file=None): """Disassemble a traceback (default: last traceback).""" if tb is None: try: tb = sys.last_traceback except AttributeError: raise RuntimeError("no last traceback to disassemble") while tb.tb_next: tb = tb.tb_next disassemble(tb.tb_frame.f_code, tb.tb_lasti, file=file) # The inspect module interrogates this dictionary to build its # list of CO_* constants. It is also used by pretty_flags to # turn the co_flags field into a human readable list.
Example #30
Source File: StackViewer.py From oss-ftp with MIT License | 5 votes |
def get_stack(self, tb): if tb is None: tb = sys.last_traceback stack = [] if tb and tb.tb_frame is None: tb = tb.tb_next while tb is not None: stack.append((tb.tb_frame, tb.tb_lineno)) tb = tb.tb_next return stack