# Python 3.2(2011/02/20) ## 新特性和改进 1. **定义稳定的ABI** - 过去,为一个 Python 版本所构建的扩展模块通常无法用于其他 Python 版本。 之所以有这样的要求是因为扩展模块可以任意访问 Python 解释器的内部对象。 - 在 Python 3.2 中,则有了一种替代方式:扩展模块将自己约束于一个受限 API(通过定义 Py_LIMITED_API)因而不能使用许多内部对象,仅限使用一组承诺会在多个发布版中保持稳定的 API 函数。 - 作为其结果,在这种模式下为 3.2 构建的扩展模块也将能在 3.3、3.4 等版本中运行。 ## 新模块和增强 1. **`concurrent.futures` 模块**: - 引入了 `concurrent.futures` 模块,提供了高级的异步编程接口,支持线程池和进程池执行器。 ```python from concurrent.futures import ThreadPoolExecutor def task(n): return n * n with ThreadPoolExecutor(max_workers=2) as executor: future = executor.submit(task, 2) print(future.result()) ``` 2. **`argparse` 模块增强**: - 改进了 `argparse` 模块,增加了新的参数类型和更好的错误处理支持,进一步简化了命令行解析。 3. **`collections` 模块增强**: - `collections` 模块新增了 `OrderedDict`、`defaultdict` 和 `Counter` 的性能优化,提升了常见数据结构的效率。