当前位置: 首页>>代码示例>>Python>>正文


Python sys.__excepthook__方法代码示例

本文整理汇总了Python中sys.__excepthook__方法的典型用法代码示例。如果您正苦于以下问题:Python sys.__excepthook__方法的具体用法?Python sys.__excepthook__怎么用?Python sys.__excepthook__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.__excepthook__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: log_excepthook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def log_excepthook(exc_class, exc_value, tb):
    import traceback

    tb_txt = ''.join(traceback.format_tb(tb))
    try:
        (filename, number, function, line_text) = traceback.extract_tb(tb)[-1]
        exc_txt = "{} line {} function {} [{}]".format(
            filename, number, function, line_text)
    except Exception:
        exc_txt = ""

    logger.error("Unhandled exception '{}' at {}"
                 .format(exc_value, exc_txt),
                 traceback=tb_txt,
                 exc_class=repr(exc_class),
                 exc_value=repr(exc_value))
    sys.__excepthook__(exc_class, exc_value, tb) 
开发者ID:KanoComputing,项目名称:kano-toolset,代码行数:19,代码来源:_logging.py

示例2: log_excepthook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def log_excepthook(exc_class, exc_value, tb):
    # at this point we have substituted the module once,
    # so we need to import all modules again
    import traceback
    import kano.logging  # Don't think about this one too hard...
    import sys

    tb_txt = ''.join(traceback.format_tb(tb))
    try:
        (filename, number, function, line_text) = traceback.extract_tb(tb)[-1]
        exc_txt = "{} line {} function {} [{}]".format(
            filename, number, function, line_text)
    except Exception:
        exc_txt = ""

    kano.logging.logger.error(
        "Unhandled exception '{}' at {} (see logfile for full trace)".format(
            exc_value, exc_txt
        ),
        traceback=tb_txt,
        exc_class=str(exc_class),
        exc_value=str(exc_value)
    )
    sys.__excepthook__(exc_class, exc_value, tb) 
开发者ID:KanoComputing,项目名称:kano-toolset,代码行数:26,代码来源:logging.py

示例3: test_unhandled

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def test_unhandled(self):
        # Check for sensible reporting of unhandled exceptions
        for exc_type in (ValueError, BrokenStrException):
            try:
                exc = exc_type("test message")
                # The following line is included in the traceback report:
                raise exc
            except exc_type:
                with captured_stderr() as stderr:
                    sys.__excepthook__(*sys.exc_info())
            report = stderr.getvalue()
            self.assertIn("test_exceptions.py", report)
            self.assertIn("raise exc", report)
            self.assertIn(exc_type.__name__, report)
            if exc_type is BrokenStrException:
                self.assertIn("<exception str() failed>", report)
            else:
                self.assertIn("test message", report)
            self.assertTrue(report.endswith("\n")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_exceptions.py

示例4: my_excepthook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def my_excepthook(type, value, tback):
    """When an exception occurs: Log the error and continue (doesn't kill the
    GUI)

    Parameters
    ----------
    type :

    value :

    tback :


    Returns
    -------

    """
    # log the exception here (Not needed with stderr redirect)

    # then call the default handler
    sys.__excepthook__(type, value, tback) 
开发者ID:Eomys,项目名称:pyleecan,代码行数:23,代码来源:__init__.py

示例5: uncaught_exception_handler

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def uncaught_exception_handler(exception_type, exception_value,
                               exception_traceback):
  """Handles any exception that are uncaught by logging an error and calling
  the sys.__excepthook__."""
  # Ensure that we are not calling ourself. This shouldn't be needed since we
  # are using sys.__excepthook__. Do this check anyway since if we are somehow
  # calling ourself we might infinitely send errors to the logs, which would be
  # quite bad.
  global _is_already_handling_uncaught
  if _is_already_handling_uncaught:
    raise Exception('Loop in uncaught_exception_handler')
  _is_already_handling_uncaught = True

  # Use emit since log_error needs sys.exc_info() to return this function's
  # arguments to call init properly.
  # Don't worry about emit() throwing an Exception, python will let us know
  # about that exception as well as the original one.
  emit(
      logging.ERROR,
      'Uncaught exception',
      exc_info=(exception_type, exception_value, exception_traceback))

  sys.__excepthook__(exception_type, exception_value, exception_traceback) 
开发者ID:google,项目名称:clusterfuzz,代码行数:25,代码来源:logs.py

示例6: runcode

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def runcode(self, code):
        """Execute a code object.

        When an exception occurs, self.showtraceback() is called to
        display a traceback.  All exceptions are caught except
        SystemExit, which is reraised.

        A note about KeyboardInterrupt: this exception may occur
        elsewhere in this code, and may not always be caught.  The
        caller should be prepared to deal with it.

        """
        try:
            Exec(code, self.frame.f_globals, self.frame.f_locals)
            pydevd_save_locals.save_locals(self.frame)
        except SystemExit:
            raise
        except:
            # In case sys.excepthook called, use original excepthook #PyDev-877: Debug console freezes with Python 3.5+
            # (showtraceback does it on python 3.5 onwards)
            sys.excepthook = sys.__excepthook__
            try:
                self.showtraceback()
            finally:
                sys.__excepthook__ = sys.excepthook 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:27,代码来源:pydevd_console.py

示例7: register_debug_hook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def register_debug_hook():
    import traceback

    def info(type, value, tb):
        if hasattr(sys, 'ps1') or not sys.stderr.isatty():
            sys.__excepthook__(type, value, tb)
        else:
            try:
                import ipdb as pdb_api
            except ImportError:
                import pdb as pdb_api
            traceback.print_exception(type, value, tb)
            pdb_api.post_mortem(tb)

    sys.excepthook = info
    logging.basicConfig(level="DEBUG") 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:18,代码来源:utils.py

示例8: setup_logging

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def setup_logging(self):

        from logbook.compat import redirect_logging
        from logbook import INFO, Logger

        redirect_logging()
        self.components['log'].handler.level = INFO
        self.components['log'].handler.push_application()

        self._logger = Logger(self.name)

        def handle_exception(exc_type, exc_value, exc_traceback):

            if issubclass(exc_type, KeyboardInterrupt):
                sys.__excepthook__(exc_type, exc_value, exc_traceback)
                return

            self._logger.error("Uncaught exception occurred",
                               exc_info=(exc_type, exc_value, exc_traceback))

        sys.excepthook = handle_exception 
开发者ID:CadQuery,项目名称:CQ-editor,代码行数:23,代码来源:main_window.py

示例9: showtraceback

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [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

示例10: interactive_exception

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def interactive_exception(e_class, e_value, tb):
    sys.__excepthook__(e_class, e_value, tb)
    tb_stack = extract_tb(tb)
    locals_stack = []
    while tb is not None:
        locals_stack.append(tb.tb_frame.f_locals)
        tb = tb.tb_next
    while len(tb_stack) > 0:
        frame = tb_stack.pop()
        ls = locals_stack.pop()
        print('\nInterpreter at file "{}", line {}, in {}:'.format(
            frame.filename, frame.lineno, frame.name))
        print('  {}'.format(frame.line.strip()))
        interact(local=ls)
#sys.excepthook = interactive_exception

# check dirs 
开发者ID:salesforce,项目名称:nonauto-nmt,代码行数:19,代码来源:self_learn.py

示例11: 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

示例12: didyoumean_disablehook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def didyoumean_disablehook():
    """Function to set hooks to their normal value."""
    sys.excepthook = sys.__excepthook__
    set_ipython_custom_exc(None)

# NOTE: It could be funny to have a magic command in Python
# https://ipython.org/ipython-doc/dev/config/custommagics.html 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:9,代码来源:didyoumean_api.py

示例13: register_excepthook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def register_excepthook(logger):
    def log_excep(exc_type, exc_value, exc_traceback):
        if issubclass(exc_type, KeyboardInterrupt):
            sys.__excepthook__(exc_type, exc_value, exc_traceback)
            return
        logger.debug(
            "Traceback",
            exc_info=(exc_type, exc_value, exc_traceback)
        )
        logger.critical(
            "Uncaught exception",
            exc_info=(exc_type, exc_value, None)
        )
    sys.excepthook = log_excep 
开发者ID:simnibs,项目名称:simnibs,代码行数:16,代码来源:simnibs_logger.py

示例14: except_hook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def except_hook(cls, exception, traceback):
    QtWidgets.QMessageBox.critical(None, 'SimNIBS GUI Error', str(exception))
    sys.__excepthook__(cls, exception, traceback)
    #sys.exit(app.exec_()) 
开发者ID:simnibs,项目名称:simnibs,代码行数:6,代码来源:main_gui.py

示例15: debug_hook

# 需要导入模块: import sys [as 别名]
# 或者: from sys import __excepthook__ [as 别名]
def debug_hook(type_, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
        sys.__excepthook__(type_, value, tb)
    else:
        import traceback
        import pdb
        traceback.print_exception(type_, value, tb)
        print(u"\n")
        pdb.pm() 
开发者ID:jwplayer,项目名称:jwalk,代码行数:11,代码来源:__main__.py


注:本文中的sys.__excepthook__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。