python类format_tb()的实例源码

recipe-499333.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def main_function(getOptString='', numArgs=0):
    def main_decorator(maincode):
        def decorated_main(argv=[__name__]):
            try:
                opts={}
                args=[]
                if len(getOptString) > 0:
                    try:
                        opt_list, args = getopt.getopt(argv[1:], getOptString)
                        opts=dict([(x[0][1:], x[1]) for x in opt_list])
                    except getopt.error, msg:
                        raise Usage(msg)
                else:
                    args=argv[1:]
                if len(args) < numArgs:
                    raise Usage("Not enough arguments")
                return maincode(args, opts) or 0
            except KeyboardInterrupt:
                sys.exit(-1)
            except SystemExit:
                pass
            except Usage, usage:
                sys.stderr.write('%s\n%s\n' % (maincode.__doc__, usage.msg))
            except Exception, err:
                cla, exc, trbk = sys.exc_info()
                import traceback
                sys.stderr.write("Caught Exception:\n%s:%s\n%s" % (cla.__name__, str(exc), ''.join(traceback.format_tb(trbk,5))))
                sys.exit(-1)
        return decorated_main
    return main_decorator

########### Example Usage ################
external_search_command.py 文件源码 项目:Splunk_CBER_App 作者: MHaggis 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def execute(self):
        # noinspection PyBroadException
        try:
            if self._argv is None:
                self._argv = os.path.splitext(os.path.basename(self._path))[0]
            self._execute(self._path, self._argv, self._environ)
        except:
            error_type, error, tb = sys.exc_info()
            message = 'Command execution failed: ' + unicode(error)
            self._logger.error(message + '\nTraceback:\n' + ''.join(traceback.format_tb(tb)))
            sys.exit(1)
app.py 文件源码 项目:girder_worker 作者: girder 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gw_task_failure(sender=None, exception=None,
                    traceback=None, **rest):
    try:

        msg = '%s: %s\n%s' % (
            exception.__class__.__name__, exception,
            ''.join(tb.format_tb(traceback)))

        sender.job_manager.write(msg)

        _update_status(sender, JobStatus.ERROR)
    except AttributeError:
        pass
__main__.py 文件源码 项目:dash-pi 作者: andrewvaughan 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def handle_exception(ex_cls, ex, trace):
        """Catches all errors and sends them through the logger"""

        LOGGER.critical("EXCEPTION")
        LOGGER.critical(''.join(traceback.format_tb(trace)))
        LOGGER.critical('%s: %s', ex_cls, ex)
retrying.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
script.py 文件源码 项目:jenkins-epo 作者: peopledoc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def entrypoint(argv=None):
    argv = argv or sys.argv[1:]

    logging.config.dictConfig(setup_logging())
    distribution = pkg_resources.get_distribution('jenkins-epo')
    logger.info("Starting jenkins-epo %s.", distribution.version)
    logger.debug("Debug mode enabled")

    # Import modules after logging is setup
    from .cache import CACHE
    from .main import main
    from .settings import SETTINGS

    try:
        logger.debug("Executing %s.", ' '.join(argv))
        main(argv)
        logger.info("Done.")
    except bdb.BdbQuit:
        logger.info('Graceful exit from debugger.')
    except Exception as e:
        if SETTINGS.DEBUG:
            logger.error("%s: %s", type(e), e)
            post_mortem()
        else:
            logger.exception("Unhandled error:")
        sys.exit(1)
    except KeyboardInterrupt:
        # Hide ^C in terminal
        sys.stderr.write('\r')
        if SETTINGS.DEBUG:
            logger.warn("Dropping in post interrupt PDB!")
            post_mortem()
        else:
            tb = traceback.format_tb(sys.exc_info()[-1])
            tb = tb[-6:]
            logger.warn("Interrupted at:\n%s", ''.join(tb).strip())
        sys.exit(1)
    finally:
        CACHE.close()

    sys.exit(0)
retrying.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
retrying.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
retrying.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
retrying.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
retrying.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
tools.py 文件源码 项目:b92statistike 作者: stalker314314 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def exception_hook(exctype, value, tb):
    """
    Catch any unhandled exception and print its stack trace.
    Useful to see what is going on when scrapper crashes.
    """
    logger = logging.getLogger('main')
    logger.critical('{0}: {1}'.format(exctype, value))
    logger.critical(''.join(traceback.format_tb(tb)))
retrying.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
score_server.py 文件源码 项目:DL4MT 作者: thompsonb 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def exception_handler(exception_type, exception, traceback):
    print("An unexpected {} exception occurred. Traceback will be written to "
          "debug log. The error message was: {}"
          .format(exception_type.__name__, exception))
    logging.debug("Traceback:")
    for item in format_tb(traceback):
        logging.debug(item.strip())
    sys.exit(2)
###end copied portion###
retrying.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
config.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __str__(self):
        etype, evalue, etb = self.excinfo
        formatted = traceback.format_tb(etb)
        # The level of the tracebacks we want to print is hand crafted :(
        return repr(evalue) + '\n' + ''.join(formatted[2:])
failure.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, exc_class, exc_val, tb=None, address=None):
        log.debug("A failure! %s %s %s", exc_class, exc_val, format_tb(tb))
        self.exc_class = exc_class
        self.exc_val = exc_val
        self.tb = tb
        self._address = address
        unittest.TestCase.__init__(self)
retrying.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
retrying.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self.has_exception:
            return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
        else:
            return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
utils.py 文件源码 项目:Qyoutube-dl 作者: lzambella 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def format_traceback(self):
        if self.traceback is None:
            return None
        return ''.join(traceback.format_tb(self.traceback))


问题


面经


文章

微信
公众号

扫码关注公众号