當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.last_traceback方法代碼示例

本文整理匯總了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) 
開發者ID:SylvainDe,項目名稱:DidYouMean-Python,代碼行數:19,代碼來源:didyoumean_api_tests.py

示例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) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:24,代碼來源:code.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:__init__.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_compare.py

示例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, 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:18,代碼來源:run.py

示例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. 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:interactiveshell.py

示例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 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:24,代碼來源:StackViewer.py

示例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) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:24,代碼來源:pydevconsole_code_for_ironpython.py

示例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)) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:22,代碼來源:pydevconsole.py

示例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)) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:19,代碼來源:pydevconsole.py

示例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 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:20,代碼來源:runner.py

示例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 
開發者ID:zhuyifei1999,項目名稱:guppy3,代碼行數:20,代碼來源:Remote.py

示例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 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:code.py

示例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 
開發者ID:SylvainDe,項目名稱:DidYouMean-Python,代碼行數:13,代碼來源:didyoumean_api.py

示例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)) 
開發者ID:SylvainDe,項目名稱:DidYouMean-Python,代碼行數:6,代碼來源:didyoumean_api_tests.py


注:本文中的sys.last_traceback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。