__main__.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:IgDiscover 作者: NBISweden 项目源码 文件源码
def main(arguments=None):
    logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
    parser = HelpfulArgumentParser(description=__doc__, prog='igdiscover')
    parser.add_argument('--profile', default=False, action='store_true',
        help='Save profiling information to igdiscover.prof')
    parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)

    subparsers = parser.add_subparsers()
    for command_name in COMMANDS:
        module = importlib.import_module('.' + command_name, 'igdiscover')
        subparser = subparsers.add_parser(command_name,
            help=module.__doc__.split('\n')[1], description=module.__doc__)
        subparser.set_defaults(func=module.main)
        module.add_arguments(subparser)

    args = parser.parse_args(arguments)
    if not hasattr(args, 'func'):
        parser.error('Please provide the name of a subcommand to run')
    elif args.profile:
        import cProfile as profile
        profile.runctx('args.func(args)', globals(), locals(), filename='igdiscover.prof')
        logger.info('Wrote profiling data to igdiscover.prof')
    else:
        args.func(args)
    if sys.platform == 'linux':
        rself = resource.getrusage(resource.RUSAGE_SELF)
        rchildren = resource.getrusage(resource.RUSAGE_CHILDREN)
        memory_kb = rself.ru_maxrss + rchildren.ru_maxrss
        cpu_time = rself.ru_utime + rself.ru_stime + rchildren.ru_utime + rchildren.ru_stime
        cpu_time_s = format_duration(cpu_time)
        logger.info('CPU time {}. Maximum memory usage {:.3f} GB'.format(
            cpu_time_s, memory_kb / 1E6))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号