python类__excepthook__()的实例源码

logger.py 文件源码 项目:iCount 作者: tomazc 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _log_all_uncaught_exceptions(exc_type, exc_value, exc_traceback):
    """Log all uncaught exceptions in non-interactive mode.

    All python exceptions are handled by function, stored in
    ``sys.excepthook.`` By rewriting the default implementation, we
    can modify handling of all uncaught exceptions.

    Warning: modified behaviour (logging of all uncaught exceptions)
    applies only when runing in non-interactive mode.

    """
    # ignore KeyboardInterrupt
    if not issubclass(exc_type, KeyboardInterrupt):
        ROOT_LOGGER.error("", exc_info=(exc_type, exc_value, exc_traceback))

    sys.__excepthook__(exc_type, exc_value, exc_traceback)
    return


# Rewrite the default implementation os sys.excepthook to log all
# uncaught exceptions:
logger.py 文件源码 项目:janna 作者: jhlee525 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _exception_hook(exc_type, exc_value, exc_traceback):
    if exc_type.__name__ == 'StreamerError':
        node = exc_value.node
        error = exc_value.error
        # node.graph.draw(attention=node)
        logger.error('Error occured when running streamers. See graph')
        exc_type = type(error)
        exc_value = error
    elif exc_type.__name__ == 'StreamerConnError':
        node1 = exc_value.src_node
        node2 = exc_value.tgt_node
        error = exc_value.error
        # node1.graph.draw(attention=[node1, node2])
        logger.error('Error occured when running streamers. See graph')
        exc_type = type(error)
        exc_value = error
    sys.__excepthook__(exc_type, exc_value, exc_traceback)
logger.py 文件源码 项目:octario 作者: redhat-openstack 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def octario_excepthook(exc_type, exc_value, exc_traceback):
    """exception hook that sends OctarioException to log and other

    exceptions to stderr (default excepthook)
    """
    from octario.lib.exceptions import OctarioException

    # sends full exception with trace to log
    if not isinstance(exc_value, OctarioException):
        return sys.__excepthook__(exc_type, exc_value, exc_traceback)

    if LOG.getEffectiveLevel() <= logging.DEBUG:
        formated_exception = "".join(
            traceback.format_exception(exc_type, exc_value, exc_traceback))
        LOG.error(formated_exception + exc_value.message)
    else:
        LOG.error(exc_value.message)
awsqueryrequest.py 文件源码 项目:cuny-bdif 作者: aristotle-tek 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print(traceback.print_tb(tb))
            sys.exit(1)
        else:
            print(value)
            sys.exit(1)

    return excepthook
dispatcher.py 文件源码 项目:rcli 作者: contains-io 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def main():
    # type: () -> typing.Any
    """Parse the command line options and launch the requested command.

    If the command is 'help' then print the help message for the subcommand; if
    no subcommand is given, print the standard help message.
    """
    colorama.init(wrap=six.PY3)
    doc = usage.get_primary_command_usage()
    allow_subcommands = '<command>' in doc
    args = docopt(doc, version=settings.version,
                  options_first=allow_subcommands)
    if sys.excepthook is sys.__excepthook__:
        sys.excepthook = log.excepthook
    try:
        log.enable_logging(log.get_log_level(args))
        default_args = sys.argv[2 if args.get('<command>') else 1:]
        if (args.get('<command>') == 'help' and
                None not in settings.subcommands):
            subcommand = next(iter(args.get('<args>', default_args)), None)
            return usage.get_help_usage(subcommand)
        argv = [args.get('<command>')] + args.get('<args>', default_args)
        return _run_command(argv)
    except exc.InvalidCliValueError as e:
        return str(e)
funcs.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def paste_traceback(exc_type, exc, tb):
    """
    This is a traceback handler that knows how to paste to the pastebin.
    Should only be used in sys.excepthook.
    """
    sys.__excepthook__(exc_type, exc, tb)
    from yt.extern.six.moves import StringIO, xmlrpc_client
    p = xmlrpc_client.ServerProxy(
            "http://paste.yt-project.org/xmlrpc/",
            allow_none=True)
    s = StringIO()
    traceback.print_exception(exc_type, exc, tb, file=s)
    s = s.getvalue()
    ret = p.pastes.newPaste('pytb', s, None, '', '', True)
    print()
    print("Traceback pasted to http://paste.yt-project.org/show/%s" % (ret))
    print()
test_exceptions.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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"))
test_sys.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_original_excepthook(self):
        savestderr = sys.stderr
        err = cStringIO.StringIO()
        sys.stderr = err

        eh = sys.__excepthook__

        self.assertRaises(TypeError, eh)
        try:
            raise ValueError(42)
        except ValueError, exc:
            eh(*sys.exc_info())

        sys.stderr = savestderr
        self.assertTrue(err.getvalue().endswith("ValueError: 42\n"))

    # FIXME: testing the code for a lost or replaced excepthook in
    # Python/pythonrun.c::PyErr_PrintEx() is tricky.
test_exceptions.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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"))
test_sys.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_original_excepthook(self):
        savestderr = sys.stderr
        err = cStringIO.StringIO()
        sys.stderr = err

        eh = sys.__excepthook__

        self.assertRaises(TypeError, eh)
        try:
            raise ValueError(42)
        except ValueError, exc:
            eh(*sys.exc_info())

        sys.stderr = savestderr
        self.assertTrue(err.getvalue().endswith("ValueError: 42\n"))

    # FIXME: testing the code for a lost or replaced excepthook in
    # Python/pythonrun.c::PyErr_PrintEx() is tricky.
server.py 文件源码 项目:borgcube 作者: enkore 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def exit_by_exception():
    class SignalException(BaseException):
        pass

    def signal_fork(signum, stack_frame):
        log.info('Received signal %d, procuring hariki', signum)
        raise SignalException(signum)

    def excepthook(exc_type, exc_value, exc_trace):
        if exc_type is SignalException:
            sys.exit(1)
        else:
            sys.__excepthook__(exc_type, exc_value, exc_trace)

    sys.excepthook = excepthook
    signal.signal(signal.SIGINT, signal_fork)
    signal.signal(signal.SIGTERM, signal_fork)
awsqueryrequest.py 文件源码 项目:learneveryword 作者: karan 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print(traceback.print_tb(tb))
            sys.exit(1)
        else:
            print(value)
            sys.exit(1)

    return excepthook
debug.py 文件源码 项目:e2end 作者: oplatek 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def exc_info_hook(exc_type, value, tb):
    """An exception hook that starts IPdb automatically on error if in interactive mode."""

    if hasattr(sys, 'ps1') or not sys.stderr.isatty() or exc_type == KeyboardInterrupt:
        # we are in interactive mode, we don't have a tty-like
        # device,, or the user triggered a KeyboardInterrupt,
        # so we call the default hook
        sys.__excepthook__(exc_type, value, tb)
    else:
        import traceback
        import ipdb
        # we are NOT in interactive mode, print the exception
        traceback.print_exception(exc_type, value, tb)
        # then start the debugger in post-mortem mode.
        # pdb.pm() # deprecated
        ipdb.post_mortem(tb)  # more modern
test_sys.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_original_excepthook(self):
        savestderr = sys.stderr
        err = cStringIO.StringIO()
        sys.stderr = err

        eh = sys.__excepthook__

        self.assertRaises(TypeError, eh)
        try:
            raise ValueError(42)
        except ValueError, exc:
            eh(*sys.exc_info())

        sys.stderr = savestderr
        self.assertTrue(err.getvalue().endswith("ValueError: 42\n"))

    # FIXME: testing the code for a lost or replaced excepthook in
    # Python/pythonrun.c::PyErr_PrintEx() is tricky.
test_sys.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_original_excepthook(self):
        savestderr = sys.stderr
        err = cStringIO.StringIO()
        sys.stderr = err

        eh = sys.__excepthook__

        self.assertRaises(TypeError, eh)
        try:
            raise ValueError(42)
        except ValueError, exc:
            eh(*sys.exc_info())

        sys.stderr = savestderr
        self.assertTrue(err.getvalue().endswith("ValueError: 42\n"))

    # FIXME: testing the code for a lost or replaced excepthook in
    # Python/pythonrun.c::PyErr_PrintEx() is tricky.
awsqueryrequest.py 文件源码 项目:Chromium_DepotTools 作者: p07r0457 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print traceback.print_tb(tb)
            sys.exit(1)
        else:
            print value
            sys.exit(1)

    return excepthook
awsqueryrequest.py 文件源码 项目:node-gn 作者: Shouqun 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print traceback.print_tb(tb)
            sys.exit(1)
        else:
            print value
            sys.exit(1)

    return excepthook
debug.py 文件源码 项目:sysl 作者: anz-bank 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def _hook(type_, value, tback):
    """Exception hook callback."""
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
        # we are in interactive mode or we don't have a tty-like
        # device, so we call the default hook
        sys.__excepthook__(type_, value, tback)
    else:
        import traceback
        import pdb
        # we are NOT in interactive mode, print the exception...
        traceback.print_exception(type_, value, tback)

        # Dirty hack because Py27 doesn't chain exceptions
        if value.args:
            tb2 = value.args[-1]
            if isinstance(tb2, type(tback)):
                ex = value.args[-2]
                print >>sys.stderr, '{}Caused by{} '.format(
                    ansi('1;35m'), ansi('0m')),
                traceback.print_exception(type_(ex), ex, tb2)

            print
        # ...then start the debugger in post-mortem mode.
        # pdb.pm() # deprecated
        pdb.post_mortem(tback)  # more "modern"
resdk_logger.py 文件源码 项目:resolwe-bio-py 作者: genialis 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _log_all_uncaught_exceptions(exc_type, exc_value, exc_traceback):
    """Log all uncaught exceptions in non-interactive mode.

    All python exceptions are handled by function, stored in
    ``sys.excepthook.`` By rewriting the default implementation, we
    can modify handling of all uncaught exceptions.

    Warning: modified behaviour (logging of all uncaught exceptions)
    applies only when runing in non-interactive mode.

    """
    # ignore KeyboardInterrupt
    if not issubclass(exc_type, KeyboardInterrupt):
        ROOT_LOGGER.error("", exc_info=(exc_type, exc_value, exc_traceback))

    sys.__excepthook__(exc_type, exc_value, exc_traceback)
    return


# Rewrite the default implementation os sys.excepthook to log all
# uncaught exceptions:
awsqueryrequest.py 文件源码 项目:alfred-ec2 作者: SoMuchToGrok 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print(traceback.print_tb(tb))
            sys.exit(1)
        else:
            print(value)
            sys.exit(1)

    return excepthook
xlsxError.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def except_hook(typ, val, tb):
    """
    traceback,?:?
    """
    pywinerr_list = []
    sys.__excepthook__(typ, val, tb)
    ex = "\n"

    for e in traceback.format_exception(typ, val, tb):
        ex += e

    pywinerr_pos = ex.find('com_error')

    if pywinerr_pos > -1:
        error_str =  ex[pywinerr_pos+len('com_error')+1:].strip()
        xt.str2List(error_str[1:-1], pywinerr_list)
    return False
    #xt.inputList(pywinerr_list)
logger.py 文件源码 项目:infrared 作者: redhat-openstack 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def ir_excepthook(exc_type, exc_value, exc_traceback):
    """
    exception hook that sends IRException to log and other exceptions to
    stderr (default excepthook)
    """

    # sends full exception with trace to log
    if not isinstance(exc_value, exceptions.IRException):
        return sys.__excepthook__(exc_type, exc_value, exc_traceback)

    if LOG.getEffectiveLevel() <= logging.DEBUG:
        formated_exception = "".join(
            traceback.format_exception(exc_type, exc_value, exc_traceback))
        LOG.error(formated_exception + exc_value.message)
    else:
        LOG.error(exc_value.message)
awsqueryrequest.py 文件源码 项目:depot_tools 作者: webrtc-uwp 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def boto_except_hook(debugger_flag, debug_flag):
    def excepthook(typ, value, tb):
        if typ is bdb.BdbQuit:
            sys.exit(1)
        sys.excepthook = sys.__excepthook__

        if debugger_flag and sys.stdout.isatty() and sys.stdin.isatty():
            if debugger.__name__ == 'epdb':
                debugger.post_mortem(tb, typ, value)
            else:
                debugger.post_mortem(tb)
        elif debug_flag:
            print traceback.print_tb(tb)
            sys.exit(1)
        else:
            print value
            sys.exit(1)

    return excepthook
osdagMainPage.py 文件源码 项目:Osdag 作者: osdag-admin 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def the_exception_hook(exctype, value, traceback):
        '''Finds the error occurs when Osdag crashes

        Args:
            exctype: type of error
            value: information of the error
            traceback: trace the object

        Returns:
            system exit(1)
        '''
        # Print the error and traceback
        print "Error occurred: ", (exctype, value, traceback)
        # Call the normal Exception hook after
        sys.__excepthook__(exctype, value, traceback)
        sys.exit(1)

    # Set the exception hook to our wrapping function
FunKeyCIA.py 文件源码 项目:FunKeyCIA 作者: llakssz 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def exceptionhandler(exctype, value, traceback):
    if exctype == IndexError:
        parser.print_usage()
    else:
        sys.__excepthook__(exctype, value, traceback)

# Set the system exception handler to the above definition.
pjf_logger.py 文件源码 项目:PyJFuzz 作者: mseclab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def init_logger():
        logging.basicConfig(filename="pjf_{0}.log".format(time.strftime("%d_%m_%Y")), level=PYJFUZZ_LOGLEVEL)
        logger = logging.getLogger(__name__)
        sys.tracebacklimit = 10

        def handle_exception(exc_type, exc_value, exc_traceback):
            if issubclass(exc_type, KeyboardInterrupt):
                sys.__excepthook__(exc_type, exc_value, exc_traceback)
                return
            logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
            sys.__excepthook__(exc_type, exc_value, None)
            return

        sys.excepthook = handle_exception
        return logger
logging.py 文件源码 项目:Harmonbot 作者: Harmon758 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def log_exception(exc_type, exc_value, exc_traceback):
    sys.__excepthook__(exc_type, exc_value, exc_traceback)
    errors_logger.error("Uncaught exception\n", exc_info = (exc_type, exc_value, exc_traceback))
openwpm_wrapper.py 文件源码 项目:PrivacyScore 作者: PrivacyScore 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def handle_exception(exc_type, exc_value, exc_traceback):
    if issubclass(exc_type, KeyboardInterrupt):
        sys.__excepthook__(exc_type, exc_value, exc_traceback)
        return

    logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
DebugHook.py 文件源码 项目:zeronet-debian 作者: bashrc 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def handleError(*args):
    global last_error
    if not args:  # Manual called
        args = sys.exc_info()
        silent = True
    else:
        silent = False
    if args[0].__name__ != "Notify":
        last_error = args
    if not silent and args[0].__name__ != "Notify":
        logging.exception("Unhandled exception")
        sys.__excepthook__(*args)


# Ignore notify errors
DebugHook.py 文件源码 项目:zeronet-debian 作者: bashrc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def handleErrorNotify(*args):
    if args[0].__name__ != "Notify":
        logging.exception("Unhandled exception")
        sys.__excepthook__(*args)


问题


面经


文章

微信
公众号

扫码关注公众号