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


Python Logger.failure方法代码示例

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


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

示例1: run_python_file

# 需要导入模块: from lib.reporting.logger import Logger [as 别名]
# 或者: from lib.reporting.logger.Logger import failure [as 别名]
def run_python_file(args):
        """Run a python file as if it were the main program on the command line.

        `args` is the argument array to present as sys.argv, including the first
        element representing the file being executed.

        Lifted straight from coverage.py by Ned Batchelder

        """
        try:
            # In Py 2.x, the builtins were in __builtin__
            BUILTINS = sys.modules['__builtin__']
        except KeyError:  # pragma: no cover - not worried about Python 3 yet...
            # In Py 3.x, they're in builtins
            BUILTINS = sys.modules['builtins']

        filename = args[0]

        # Create a module to serve as __main__
        old_main_mod = sys.modules['__main__']
        main_mod = imp.new_module('__main__')
        sys.modules['__main__'] = main_mod
        main_mod.__file__ = filename
        main_mod.__builtins__ = BUILTINS

        # Set sys.argv and the first path element properly.
        old_argv = sys.argv
        old_path0 = sys.path[0]
        sys.argv = args
        sys.path[0] = os.path.dirname(filename)

        try:
            sys.stdout = open('outfile.txt', 'w')
            source = open(filename, 'rU').read()
            exec compile(source, filename, "exec") in main_mod.__dict__
        except Exception, ex:
            Logger.add_error("%s" % ex)
            Logger.failure("Exception in application")
开发者ID:rogerlindberg,项目名称:autopilot,代码行数:40,代码来源:pythonlauncher.py


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