- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
🌐 Add Chinese translation for docs/zh/docs/async.md
#3830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌐 Add Chinese translation for docs/zh/docs/async.md
#3830
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3830 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 540 410 -130
Lines 13969 10281 -3688
===========================================
- Hits 13969 10281 -3688 ☔ View full report in Codecov by Sentry. |
📝 Docs preview for commit 8769b34 at: https://612efbdca2fbfe444dff1c9c--fastapi.netlify.app |
📝 Docs preview for commit c2c9b7d at: https://613ebc557ec3e2f4558a0dab--fastapi.netlify.app |
docs/async.md
|
||
--- | ||
|
||
如果使用不支持 `await` 的第三方支持库与(数据库、API、文件系统等)对象通信,(这是绝大多数数据库支持库的现状),就要只能使用 `def` 把*路径操作函数*声明为普通函数,如下: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“就要只能使用”是什么意思?是想说"就只能使用"吗
|
||
**协程**只是个非常花哨的术语,指的是由 `async def` 函数返回的对象。Python 把它识别为可以在某些点启动或终止的函数,但它还可以在内部暂停 ⏸,只要在它的内部包含 `await`。 | ||
|
||
但是使用 `async` 与 `await` 的异步编码的这种功能尝尝被统称为“携程”。它与 Go 的核心功能 “Goroutines” 相对应。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“携程” -> “协程”
但是使用 `async` 与 `await` 的异步编码的这种功能尝尝被统称为“携程”。它与 Go 的核心功能 “Goroutines” 相对应。 | |
但是使用 `async` 与 `await` 的异步编码的这种功能尝尝被统称为“协程”。它与 Go 的核心功能 “Goroutines” 相对应。 |
|
||
使用普通 `def` 替代 `async def` 声明*路径操作函数*时,要在等待的外部线程池中运行,不能直接调用(因为它会阻塞服务器)。 | ||
|
||
如果你之前使用的异步框架不以上述方式运行,或者你习惯了定义琐碎的仅供计算的纯 `def` *路径操作函数*只为了提升些许性能(约 100 纳秒),请注意,在 **FastAPI** 中的效果正相反。在这些情况下,除非*路径操作函数*使用执行阻塞 <abbr title="输入/输出:磁盘读取与写入,网络通信d。">I/O</abbr> 的代码,最好使用 `async def`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果你之前使用的异步框架不以上述方式运行,或者你习惯了定义琐碎的仅供计算的纯 `def` *路径操作函数*只为了提升些许性能(约 100 纳秒),请注意,在 **FastAPI** 中的效果正相反。在这些情况下,除非*路径操作函数*使用执行阻塞 <abbr title="输入/输出:磁盘读取与写入,网络通信d。">I/O</abbr> 的代码,最好使用 `async def`。 | |
如果你之前使用的异步框架不以上述方式运行,或者你习惯了定义琐碎的仅供计算的普通`def` *路径操作函数*而只为了提升些许性能(约 100 纳秒),请注意,在 **FastAPI** 中的效果正相反。在这些情况下,最好使用 `aysnc def`,除非*路径操作函数*使用阻塞式 <abbr title="输入/输出:磁盘读取与写入,网络通信">I/O</abbr> 的代码。 |
📝 Docs preview for commit 99fac02 at: https://649a2380c3bf901b5aa9e53c--fastapi.netlify.app |
docs/async.md
docs/zh/docs/async.md
Thank you! It seems this one was handled in another PR, so I'll pass on this one, but feel free to add new PRs updating the current version if you think that's needed! Thanks! ☕ 🍰 |
as title