.. image:: https://img.shields.io/badge/chat-join%20now-blue.svg :target: https://gitter.im/python-trio/general :alt: 加入聊天室
.. image:: https://img.shields.io/badge/forum-join%20now-blue.svg :target: https://trio.discourse.group :alt: 加入论坛
.. image:: https://img.shields.io/badge/docs-read%20now-blue.svg :target: https://trio.readthedocs.io :alt: 文档
.. image:: https://img.shields.io/pypi/v/trio.svg :target: https://pypi.org/project/trio :alt: 最新 PyPi 版本
.. image:: https://img.shields.io/conda/vn/conda-forge/trio.svg :target: https://anaconda.org/conda-forge/trio :alt: 最新 conda-forge 版本
.. image:: https://codecov.io/gh/python-trio/trio/branch/main/graph/badge.svg :target: https://codecov.io/gh/python-trio/trio :alt: 测试覆盖率
Trio – 一个友好的 Python 异步并发与 I/O 库
.. image:: https://raw.githubusercontent.com/python-trio/trio/9b0bec646a31e0d0f67b8b6ecc6939726faf3e17/logo/logo-with-background.svg :width: 200px :align: right
Trio 项目旨在打造一款生产级质量的、
采用宽松许可证 <https://github.com/python-trio/trio/blob/main/LICENSE>__ 的
Python 原生 async/await I/O 库。与所有异步库一样,
其主要目的是帮助你编写能够同时
执行多项任务并利用并行化 I/O 的程序。一个
希望并行抓取大量页面的网络爬虫,一个需要
同时处理大量下载和 websocket 连接的 web 服务器,一个
监控多个子进程的进程管理器……就是这类
应用。与其他库相比,Trio 试图通过
对易用性和
正确性的极致关注来
确立自身特色。并发很复杂;我们努力让把事情做对变得简单。
Trio 从底层构建,充分利用了 最新的 Python 特性 <https://www.python.org/dev/peps/pep-0492/>,并
从 众多来源 <https://github.com/python-trio/trio/wiki/Reading-list> 汲取
灵感,特别是 Dave Beazley 的 Curio <https://curio.readthedocs.io/>。
由此产生的设计比 asyncio <https://docs.python.org/3/library/asyncio.html> 和
Twisted <https://twistedmatrix.com/>__ 等较老的竞争对手
要简单得多,但能力同样强大。Trio 是
我一直想要的 Python I/O 库;我发现它让构建
I/O 密集型程序变得更容易、更少出错,而且
纯粹更有趣。也许你也会发现这一点 <https://github.com/python-trio/trio/wiki/Testimonials>__。
Trio 是一个成熟且经过充分测试的项目:整体设计稳健,
现有功能均有完整文档,并广泛应用于
生产环境。虽然我们偶尔会进行小幅接口调整,
但破坏性变更极为罕见。我们鼓励您放心使用 Trio,
但如果您依赖长期 API 稳定性,请考虑订阅 issue #1 <https://github.com/python-trio/trio/issues/1>__,以便提前
获知任何兼容性更新的通知。
接下来去哪里?
我想试一试! 太好了!我们有一个友好的教程 <https://trio.readthedocs.io/en/stable/tutorial.html>__供您
入门;无需任何异步编程经验。
唉,我不想读那么多——给我看看代码! 如果您
不耐烦,那么这里有一个简单的并发示例 <https://trio.readthedocs.io/en/stable/tutorial.html#tutorial-example-tasks-intro>,
一个echo 客户端 <https://trio.readthedocs.io/en/stable/tutorial.html#tutorial-echo-client-example>,
以及一个echo 服务器 <https://trio.readthedocs.io/en/stable/tutorial.html#tutorial-echo-server-example>__。
Trio 如何让程序比竞争方案更易于阅读和推理? Trio 基于一种我们
称之为“结构化并发”的新思维方式。最好的理论介绍是
文章《Notes on structured concurrency, or: Go statement
considered harmful
https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/__。 或者,观看这场 PyCon 2018 的演讲
https://www.youtube.com/watch?v=oLkfnc_UMcE`__,以查看
在旧库与 Trio 中实现“Happy Eyeballs”算法的
演示对比。
酷,但它能在我的系统上运行吗? 很可能可以!只要你拥有
某种 Python 3.10 或更高版本(CPython 或 目前维护的 PyPy3 版本 <https://doc.pypy.org/en/latest/faq.html#which-python-versions-does-pypy-implement>__
都可以),并且使用的是 Linux、macOS、Windows 或 FreeBSD,那么 Trio
就能工作。其他环境可能也能工作,但
这些是我们进行测试的环境。而且我们的所有依赖项都是纯 Python,
除了 Windows 上的 CFFI,它有可用的 wheel,因此
安装应该很容易(不需要 C 编译器)。
我试过了,但它不起作用。 很遗憾听到这个消息!你可以尝试
在我们的 聊天室 <https://gitter.im/python-trio/general>__ or 论坛 <https://trio.discourse.group>, 提交 bug <https://github.com/python-trio/trio/issues/new>, or 在 StackOverflow 上 提问 <https://stackoverflow.com/questions/ask?tags=python+python-trio>__,
我们会尽力帮助你。
Trio 很棒,我想帮助让它更棒! 你太棒了!有很多工作要做——填补缺失的
功能,构建使用 Trio 的库生态系统,
可用性测试(例如,也许尝试教自己或朋友
使用 Trio,并列出你遇到的每个错误消息以及
你感到困惑的地方?),改进文档,……查看我们的 贡献者 指南 <https://trio.readthedocs.io/en/stable/contributing.html>__!
我目前没有立即使用它的计划,但我热衷于钻研 I/O 库设计! 这有点奇怪吗?但说实话,你会在这里如鱼得水。我们有一个 专门讨论结构化并发的子论坛 <https://trio.discourse.group/c/structured-concurrency>(欢迎其他系统的开发者!)。或者看看我们的 设计选择讨论 <https://trio.readthedocs.io/en/stable/design.html#user-level-api-principles>、
阅读列表 <https://github.com/python-trio/trio/wiki/Reading-list>,以及
标记为 design-discussion 的问题 <https://github.com/python-trio/trio/labels/design%20discussion>。
我想确保我公司的律师不会对我发火! 别担心,Trio 采用宽松的许可证,您可以选择 MIT 或
Apache 2。详见 LICENSE <https://github.com/python-trio/trio/blob/main/LICENSE>__。
行为准则
要求所有贡献者在所有项目空间中遵守我们的 行为准则 <https://trio.readthedocs.io/en/stable/code-of-conduct.html>__。