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


Python sys.excepthook方法代碼示例

本文整理匯總了Python中sys.excepthook方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.excepthook方法的具體用法?Python sys.excepthook怎麽用?Python sys.excepthook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sys的用法示例。


在下文中一共展示了sys.excepthook方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_with_api

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [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: start_gui

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def start_gui(args):
    app = QtWidgets.QApplication(args)
    #app.setAttribute(QtCore.Qt.AA_UseDesktopOpenGL)
    #app.setAttribute(QtCore.Qt.AA_UseSoftwareOpenGL)
    #app.setAttribute(QtCore.Qt.AA_UseOpenGLES)
    sys.excepthook = except_hook
    ex = TDCS_GUI()
    ex.show()
    if len(args) > 1:
        if args[1].endswith(".mat"):
            ex.openSimnibsFile(args[1])
        elif args[1].endswith(".msh"):
            ex.loadHeadModel(args[1])
        else:
            raise IOError('simnibs_gui can only load .mat and .msh files')
    sys.exit(app.exec_()) 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:18,代碼來源:main_gui.py

示例3: _getexcepthook

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def _getexcepthook():
    "Return a function that can be used as except hook for uncaught exceptions."
    if not sys.argv[0]:
        # We are in interactive mode and don't want to terminate
        return sys.excepthook
    # else create a function that terminates all spawned processes and this
    # in case of an uncaught exception
    exit = _getexitfunction()

    def excepthook(exctype, excvalue, exctraceback):
        import traceback
        sys.stderr.write(
            "An uncaught exception occured. Terminating pygrametl.\n")
        traceback.print_exception(exctype, excvalue, exctraceback)
        exit()
    return excepthook


# Stuff for @splitpoint 
開發者ID:chrthomsen,項目名稱:pygrametl,代碼行數:21,代碼來源:parallel.py

示例4: hook_exceptions

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def hook_exceptions(self, logger: logging.RootLogger) -> None:
        """Format excetion traceback.
        
        Parameters:
            logger:
                The logger for logging exceptions.
        """

        def _hook(exc_type, value, exc_tb) -> None:
            nest_dir = os.path.dirname(os.path.abspath(__file__))
            traceback_str = ''
            idx = 0
            for file_name, line_number, func_name, text in traceback.extract_tb(exc_tb)[1:]:
                # skip Nest-related tracebacks to make it more readable
                if os.path.dirname(os.path.abspath(file_name)) == nest_dir:
                    continue
                idx += 1
                traceback_str += '\n  [%d] File "%s", line %d, in function "%s"\n    %s' % \
                    (idx, file_name, line_number, func_name, text)
            if traceback_str != '':
                traceback_str = 'Traceback: ' + traceback_str
            logger.critical('Exception occurred during resolving:\nType: %s\nMessage: %s\n%s' % \
                (exc_type.__name__, value, traceback_str))

        sys.excepthook = _hook 
開發者ID:ZhouYanzhao,項目名稱:Nest,代碼行數:27,代碼來源:cli.py

示例5: __exit__

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def __exit__(self, *exc_info):
        
        if self.proc is not None:  ## worker 
            exceptOccurred = exc_info[0] is not None ## hit an exception during processing.
                
            try:
                if exceptOccurred:
                    sys.excepthook(*exc_info)
            finally:
                #print os.getpid(), 'exit'
                os._exit(1 if exceptOccurred else 0)
                
        else:  ## parent
            if self.showProgress:
                try:
                    self.progressDlg.__exit__(None, None, None)
                except Exception:
                    pass 
開發者ID:SrikanthVelpuri,項目名稱:tf-pose,代碼行數:20,代碼來源:parallelizer.py

示例6: failed

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def failed(self):
        # check, if the reason was a ConfigureDryRunError or a
        # ConfigureCacheError and if yes, reraise the exception
        exc_type = self.exc_info()[0]
        if issubclass(exc_type, SConfError):
            raise
        elif issubclass(exc_type, SCons.Errors.BuildError):
            # we ignore Build Errors (occurs, when a test doesn't pass)
            # Clear the exception to prevent the contained traceback
            # to build a reference cycle.
            self.exc_clear()
        else:
            self.display('Caught exception while building "%s":\n' %
                         self.targets[0])
            sys.excepthook(*self.exc_info())
        return SCons.Taskmaster.Task.failed(self) 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:18,代碼來源:SConf.py

示例7: _make_excepthook

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def _make_excepthook(old_excepthook):
    # type: (Excepthook) -> Excepthook
    def sentry_sdk_excepthook(type_, value, traceback):
        # type: (Type[BaseException], BaseException, TracebackType) -> None
        hub = Hub.current
        integration = hub.get_integration(ExcepthookIntegration)

        if integration is not None and _should_send(integration.always_run):
            # If an integration is there, a client has to be there.
            client = hub.client  # type: Any

            with capture_internal_exceptions():
                event, hint = event_from_exception(
                    (type_, value, traceback),
                    client_options=client.options,
                    mechanism={"type": "excepthook", "handled": False},
                )
                hub.capture_event(event, hint=hint)

        return old_excepthook(type_, value, traceback)

    return sentry_sdk_excepthook 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:24,代碼來源:excepthook.py

示例8: thunk_hook

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def thunk_hook(type, value, trace):
    """
    WRITEME

    This function is meant to replace excepthook and do some
    special work if the exception value has a __thunk_trace__
    field. In that case, it retrieves the field, which should
    contain a trace as returned by L{traceback.extract_stack},
    and prints it out on L{stderr}.

    The normal excepthook is then called.

    Notes
    -----
    This hook replaced by nosetests, so it does not run in nose tests.

    """
    log_thunk_trace(value)
    __excepthook(type, value, trace) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:21,代碼來源:link.py

示例9: failed

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def failed(self):
        # check, if the reason was a ConfigureDryRunError or a
        # ConfigureCacheError and if yes, reraise the exception
        exc_type = self.exc_info()[0]
        if issubclass(exc_type, SConfError):
            raise
        elif issubclass(exc_type, SCons.Errors.BuildError):
            # we ignore Build Errors (occurs, when a test doesn't pass)
            # Clear the exception to prevent the contained traceback
            # to build a reference cycle.
            self.exc_clear()
        else:
            self.display('Caught exception while building "%s":\n' %
                         self.targets[0])
            try:
                excepthook = sys.excepthook
            except AttributeError:
                # Earlier versions of Python don't have sys.excepthook...
                def excepthook(type, value, tb):
                    traceback.print_tb(tb)
                    print type, value
            excepthook(*self.exc_info())
        return SCons.Taskmaster.Task.failed(self) 
開發者ID:bq,項目名稱:web2board,代碼行數:25,代碼來源:SConf.py

示例10: test_running_main

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def test_running_main(exopy_qtbot, app_dir, monkeypatch):
    """Test starting the main app and closing it.

    """
    from enaml.workbench.ui.ui_plugin import UIPlugin

    def wait_for_window(self):
        pass

    # Do not release the application
    def no_release(self):
        pass

    monkeypatch.setattr(UIPlugin, '_release_application', no_release)
    monkeypatch.setattr(UIPlugin, 'start_application', wait_for_window)

    import sys
    old = sys.excepthook
    try:
        main([])
    finally:
        sys.excepthook = old 
開發者ID:Exopy,項目名稱:exopy,代碼行數:24,代碼來源:test___main__.py

示例11: main

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def main():
    '''
        Main entry point for Spark Streaming Listener functionality.
    '''
    try: streaming_listener(**parse_args().__dict__)
    except SystemExit: raise
    except:
        sys.excepthook(*sys.exc_info())
        sys.exit(1) 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:11,代碼來源:listener.py

示例12: _exitfunc

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def _exitfunc(cls):
        # At shutdown invoke finalizers for which atexit is true.
        # This is called once all other non-daemonic threads have been
        # joined.
        reenable_gc = False
        try:
            if cls._registry:
                import gc
                if gc.isenabled():
                    reenable_gc = True
                    gc.disable()
                pending = None
                while True:
                    if pending is None or finalize._dirty:
                        pending = cls._select_for_exit()
                        finalize._dirty = False
                    if not pending:
                        break
                    f = pending.pop()
                    try:
                        # gc is disabled, so (assuming no daemonic
                        # threads) the following is the only line in
                        # this function which might trigger creation
                        # of a new finalizer
                        f()
                    except Exception:
                        sys.excepthook(*sys.exc_info())
                    assert f not in cls._registry
        finally:
            # prevent any more finalizers from executing during shutdown
            finalize._shutdown = True
            if reenable_gc:
                gc.enable() 
開發者ID:kislyuk,項目名稱:aegea,代碼行數:35,代碼來源:weakref.py

示例13: install_mpi_excepthook

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def install_mpi_excepthook():
    import sys
    from mpi4py import MPI
    old_hook = sys.excepthook

    def new_hook(a, b, c):
        old_hook(a, b, c)
        sys.stdout.flush()
        sys.stderr.flush()
        MPI.COMM_WORLD.Abort()
    sys.excepthook = new_hook 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:13,代碼來源:util.py

示例14: std_exceptions

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def std_exceptions(etype, value, tb):
    sys.excepthook = sys.__excepthook__
    if issubclass(etype, KeyboardInterrupt):
        pass
    elif issubclass(etype, IOError) and value.errno == errno.EPIPE:
        pass
    else:
        sys.__excepthook__(etype, value, tb) 
開發者ID:pywren,項目名稱:pywren-ibm-cloud,代碼行數:10,代碼來源:ps_mem.py

示例15: didyoumean_hook

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import excepthook [as 別名]
def didyoumean_hook(type_, value, traceback, prev_hook=sys.excepthook):
    """Hook to be substituted to sys.excepthook to enhance exceptions."""
    add_suggestions_to_exception(type_, value, traceback)
    return prev_hook(type_, value, traceback) 
開發者ID:SylvainDe,項目名稱:DidYouMean-Python,代碼行數:6,代碼來源:didyoumean_api.py


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