当前位置: 首页>>代码示例>>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;未经允许,请勿转载。