Stevedore - (Dynamic Code Patterns: Extending Your Applications with Plugins)

Dynamic Code Patterns: Extending Your Applications with Plugins      Download this deck  in here.


The ExtensionManager is created slightly differently from the DriverManager because it does not need to know in advance which plugin to load. It loads all of the plugins it finds.

    mgr = extension.ExtensionManager(
        namespace='stevedore.example.formatter',
        invoke_on_load=True,
        invoke_args=(parsed_args.width,),
    )

To call the plugins, use the map() method, passing a callable to be invoked for each extension. The format_data() function used withmap() in this example takes two arguments, the Extension and the data argument given to map().

    def format_data(ext, data):
        return (ext.name, ext.obj.format(data))

    results = mgr.map(format_data, data)

The Extension passed format_data() is a class defined by stevedore that wraps the plugin. It includes the name of the plugin, theEntryPoint returned by pkg_resources, and the plugin itself (the named object referenced by the plugin definition). Wheninvoke_on_load is true, the Extension will also have an obj attribute containing the value returned when the plugin was invoked.

map() returns a sequence of the values returned by the callback function. In this case, format_data() returns a tuple containing the extension name and the iterable that produces the text to print. As the results are processed, the name of each plugin is printed and then the formatted data.

    for name, result in results:
        print('Formatter: {0}'.format(name))
        for chunk in result:
            print(chunk, end='')
        print('')



Why Not Call Plugins Directly?

Using a separate callable argument to map(), rather than just invoking the plugin directly introduces a separation between your application code and the plugins. The benefits of this separation manifest in the application code design and in the plugin API design.

If map() called the plugin directly, each plugin would have to be a callable. That would mean a separate namespace for what is really just a method of the plugin. By using a separate callable argument, the plugin API does not need to match exactly any particular use case in the application. This frees you to create a finer-grained API, with more individual methods that can be called in different ways to achieve different goals.



内容概要:本文为中国信息通信研究院发布的《2024年大模型落地路线图研究报告》,旨在梳理大模型应用落地的共性需求和关键要素,为大模型赋能各行业提供参考。报告重点介绍了大模型应用落地的四个重要阶段——现状诊断、能力建设、应用部署、运营管理,归纳了八个关键步骤,包括能力分析、需求挖掘、方案设计、研发测试、应用开发、效能评估、运维监测和运营管理。报告详细分析了大模型在基础设施、数据资源、算法模型、应用服务、安全可信五个层面应重点关注的发展要素和亟待解决的问题。此外,报告还探讨了大模型在金融、工业、教育、医疗、政务等行业的具体应用场景及其带来的降本增效、提质增效等优势。最后,报告展望了大模型的发展趋势,强调了架构优化、行业数字化转型和可信发展的必要性。 适合人群:具备一定技术背景,特别是从事人工智能、大数据、云计算等领域工作的研发人员、管理人员和技术决策者。 使用场景及目标:①帮助企业和机构评估自身大模型应用的基础条件,明确业务转型需求;②指导大模型建设方案的设计和实施,确保技术选型的科学性和合理性;③提供应用部署和效能评估的具体方法,确保大模型在实际应用中的稳定性和高效性;④建立健全大模型的运营管理体系,保障业务的高效稳定开展。 其他说明:报告强调了大模型在推动各行业数字化转型中的重要作用,提出了未来大模型发展的重点方向,如架构优化、技术应用和可信发展。报告还呼吁社会各界共同关注大模型的安全可信问题,确保其与人类价值观的对齐,推动大模型的健康发展。
软考初级程序员是中国计算机技术与软件专业技术资格(水平)考试中的一个重要级别,主要面向打算进入IT行业的初学者或初级程序员。这个级别的考试旨在测试考生的基础编程能力、计算机基础知识以及解决问题的能力。历年真题是备考的重要参考资料,可以帮助考生了解考试的题型、难度以及考点。 在"软考初级程序员09-18年真题及答案解析"的压缩包中,包含了从2009年至2018年上半年的所有程序员考试真题。这些真题涵盖了多个方面,包括但不限于: 1. **基础编程语言**:如C语言、Java、Python等,主要考察基本语法、数据类型、控制结构、函数使用等方面。 2. **数据结构与算法**:如数组、链表、栈、队列、树、图等,以及排序算法(冒泡、选择、插入、快速、归并等)和查找算法(线性查找、二分查找等)。 3. **计算机系统知识**:包括计算机组成原理、操作系统、网络基础知识,例如CPU结构、内存管理、进程与线程、网络协议等。 4. **数据库基础**:SQL语言的基本操作,如增删改查、子查询、联接操作、索引等。 5. **软件工程与项目管理**:软件生命周期、需求分析、设计原则、测试方法、版本控制等。 6. **法律法规与职业道德**:涉及知识产权、合同法、信息安全与隐私保护等。 每份真题后的答案解析部分,是对题目答案的详细解释,通常包括解题思路、关键步骤以及知识点的扩展。通过阅读解析,考生不仅能知道自己答案的正确与否,还能深入理解相关知识点,提高自己的分析和解决问题的能力。 在准备软考初级程序员考试时,考生应充分利用这些真题资源,进行模拟练习,掌握各类题目的解答技巧。同时,考生还需要广泛阅读教材,补充相关知识,提高对理论的理解。此外,多做编程实践,提高实际编程能力,也是非常重要的。 总结来说,这个压缩包是备考软考初级程序员的宝贵资料,它能帮助考生熟悉考试形式,了解重
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值