generated from flaskcwg/translation-template
-
Notifications
You must be signed in to change notification settings - Fork 22
Translate async-await #24
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
Open
rosekc
wants to merge
7
commits into
flaskcwg:main
Choose a base branch
from
rosekc:translate-async-await
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9cb04e7
Assign async-await to @rosekc
rosekc 3f65caa
Merge branch 'main' into assign-async-await
rosekc 0c75ad1
Translate async-await
rosekc 139dd74
Apply suggestions from code review
rosekc 01b76c6
Merge remote-tracking branch 'greyli/main' into translate-async-await
rosekc edab285
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b014948
Fix typos & sync with upstream
rosekc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,4 +85,3 @@ msgid "" | |
"must build with caution, watching for exploits when building to your " | ||
"requirements." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6613,4 +6613,3 @@ msgstr "" | |
|
||
#~ msgid "Raises" | ||
#~ msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ msgstr "" | |
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2021-05-30 19:27+0000\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Last-Translator: rosekc <[email protected]>\n" | ||
"Language-Team: zh_CN <[email protected]>\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
|
@@ -19,7 +19,7 @@ msgstr "" | |
|
||
#: ../../async-await.rst:4 | ||
msgid "Using ``async`` and ``await``" | ||
msgstr "" | ||
msgstr "使用 ``async`` 和 ``await``" | ||
|
||
#: ../../async-await.rst:8 | ||
msgid "" | ||
|
@@ -29,21 +29,28 @@ msgid "" | |
"where ``contextvars.ContextVar`` is available. This allows views to be " | ||
"defined with ``async def`` and use ``await``." | ||
msgstr "" | ||
"只要在安装 Flask 时加上 ``async`` 额外依赖(``pip install flask[async]``)," | ||
"包括路由、错误处理、请求前、请求后以及清理(teardown)的函数都可以使用协程函数。" | ||
"这需要 Python 3.7+ 的环境,以提供 ``contextvars.ContextVar`` 的支持。" | ||
"这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。" | ||
|
||
#: ../../async-await.rst:21 | ||
msgid "Using ``async`` on Windows on Python 3.8" | ||
msgstr "" | ||
msgstr "在 Windows,Python 3.8 环境下使用 ``async``" | ||
|
||
#: ../../async-await.rst:23 | ||
msgid "" | ||
"Python 3.8 has a bug related to asyncio on Windows. If you encounter " | ||
"something like ``ValueError: set_wakeup_fd only works in main thread``, " | ||
"please upgrade to Python 3.9." | ||
msgstr "" | ||
"在 Windows,Python 3.8 环境下存在一个与 asyncio 相关的 bug。如果遇到" | ||
"类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息," | ||
"请升级到 Python 3.9。" | ||
|
||
#: ../../async-await.rst:29 | ||
msgid "Performance" | ||
msgstr "" | ||
msgstr "性能" | ||
|
||
#: ../../async-await.rst:31 | ||
msgid "" | ||
|
@@ -52,6 +59,9 @@ msgid "" | |
" request comes in to an async view, Flask will start an event loop in a " | ||
"thread, run the view function there, then return the result." | ||
msgstr "" | ||
"异步函数需要一个事件循环来执行。作为一个 WSGI 应用,Flask 使用一个线程去处理" | ||
"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件" | ||
"循环,在这个事件循环中执行视图函数,然后返回结果。" | ||
|
||
#: ../../async-await.rst:36 | ||
msgid "" | ||
|
@@ -61,6 +71,9 @@ msgid "" | |
"etc. However, the number of requests your application can handle at one " | ||
"time will remain the same." | ||
msgstr "" | ||
"即使使用异步视图函数,每一个请求依然与一个线程绑定在一起。这样设计的好处是让" | ||
"视图函数中可以执行异步代码,例如多个并行的数据库查询,HTTP 请求外部 API 等等。" | ||
"然而,同一时间应用本身能接受的请求数量不会改变。" | ||
|
||
#: ../../async-await.rst:42 | ||
msgid "" | ||
|
@@ -70,10 +83,13 @@ msgid "" | |
"most use cases, but Flask's async support enables writing and using code " | ||
"that wasn't possible natively before." | ||
msgstr "" | ||
"**异步并不一定比同步代码快。** 异步的优势是在 IO 密集任务上,但是在 CPU 密集任务上" | ||
"则不然。传统的 Flask 视图函数在大多数情况下是合适的选择,而 Flask 对异步的支持让" | ||
"运行和使用协程代码成为可能,这是以前原生环境无法做到的。" | ||
|
||
#: ../../async-await.rst:50 | ||
msgid "Background tasks" | ||
msgstr "" | ||
msgstr "后台任务" | ||
|
||
#: ../../async-await.rst:52 | ||
msgid "" | ||
|
@@ -83,6 +99,9 @@ msgid "" | |
"cancelled. Therefore you cannot spawn background tasks, for example via " | ||
"``asyncio.create_task``." | ||
msgstr "" | ||
"异步函数在其执行完成前,都一个事件循环中运行。当异步函数完成时,事件循环也将停止。" | ||
"这意味着异步函数完成的时候,所有尚未完成的其他衍生任务都将被取消。因此,不能使用" | ||
"类似 ``asyncio.create_task`` 的方法来创建后台任务。" | ||
|
||
#: ../../async-await.rst:58 | ||
msgid "" | ||
|
@@ -93,10 +112,14 @@ msgid "" | |
":ref:`asgi`. This works as the adapter creates an event loop that runs " | ||
"continually." | ||
msgstr "" | ||
"要使用后台任务,最好的方法就是使用任务队列去激活后台任务,而不是在视图函数中" | ||
"创建。考虑到这点,使用 ASGI 服务器来为 Flask 提供服务来创建后台任务,然后如" | ||
" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这起作用是因为" | ||
"适配器创建了一个持续运行的事件循环。" | ||
|
||
#: ../../async-await.rst:67 | ||
msgid "When to use Quart instead" | ||
msgstr "" | ||
msgstr "何时使用 Quart 作为替代品" | ||
|
||
#: ../../async-await.rst:69 | ||
msgid "" | ||
|
@@ -107,6 +130,10 @@ msgid "" | |
"handle many concurrent requests, long running requests, and websockets " | ||
"without requiring multiple worker processes or threads." | ||
msgstr "" | ||
"基于实现上的不同,Flask 的异步支持的性能比异步优先的框架会稍低。如果已经拥有" | ||
"一个以异步为主的代码库,考虑使用 `Quart`_ 会更合理。Quart 是一个基于 `ASGI`_ " | ||
"的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行" | ||
"的请求,以及 websockets 编程不再需要多个工作进程或线程。" | ||
|
||
#: ../../async-await.rst:76 | ||
msgid "" | ||
|
@@ -117,10 +144,14 @@ msgid "" | |
"whether you should use Flask, Quart, or something else is ultimately up " | ||
"to understanding the specific needs of your project." | ||
msgstr "" | ||
"其实当前已经可以使用 Gevent 或 Eventlet 运行 Flask 来获得异步请求处理的好处。" | ||
"这些库通过为底层 Python 库打补丁的方式实现,而 ``async``/``await`` 与 ASGI" | ||
"使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于" | ||
"对项目的具体需求的理解。" | ||
|
||
#: ../../async-await.rst:88 | ||
msgid "Extensions" | ||
msgstr "" | ||
msgstr "扩展" | ||
|
||
#: ../../async-await.rst:90 | ||
msgid "" | ||
|
@@ -131,6 +162,10 @@ msgid "" | |
"awaitable either and will probably be blocking if called within an async " | ||
"view." | ||
msgstr "" | ||
"Flask 扩展系统的实现先于 Flask 异步支持,所以并不会假设视图函数是异步的。如果扩展" | ||
"提供了对视图函数的有附加功能的装饰器,这些装饰器因为不会异步等待(await)函数运行或者不是" | ||
"异步可等待(awaitable)的,在异步视图函数上可能不能正常运行。扩展提供的其他函数或许" | ||
"同样不是异步可等待的,在异步视图函数中调用的时候大概率会阻塞。" | ||
|
||
#: ../../async-await.rst:96 | ||
msgid "" | ||
|
@@ -139,23 +174,28 @@ msgid "" | |
"provides a view function decorator add ``ensure_sync`` before calling the" | ||
" decorated function," | ||
msgstr "" | ||
"扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。" | ||
"举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。" | ||
|
||
#: ../../async-await.rst:111 | ||
msgid "" | ||
"Check the changelog of the extension you want to use to see if they've " | ||
"implemented async support, or make a feature request or PR to them." | ||
msgstr "" | ||
"检查扩展的更新记录,查看是否实现了异步支持。如果没有可以向他们提交 PR。" | ||
|
||
#: ../../async-await.rst:116 | ||
msgid "Other event loops" | ||
msgstr "" | ||
msgstr "其他事件循环" | ||
|
||
#: ../../async-await.rst:118 | ||
msgid "" | ||
"At the moment Flask only supports :mod:`asyncio`. It's possible to " | ||
"override :meth:`flask.Flask.ensure_sync` to change how async functions " | ||
"are wrapped to use a different library." | ||
msgstr "" | ||
"当前 Flask 只支持 :mod:`asyncio`。通过覆写 :meth:`flask.Flask.ensure_sync` " | ||
"来修改包裹异步函数的实现,以使用其他的库。" | ||
|
||
#~ msgid "" | ||
#~ "Routes, error handlers, before request, " | ||
|
@@ -166,4 +206,3 @@ msgstr "" | |
#~ " allows views to be defined with " | ||
#~ "``async def`` and use ``await``." | ||
#~ msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,4 +375,3 @@ msgstr "" | |
#: ../../blueprints.rst:302 | ||
msgid "See :doc:`/errorhandling`." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2556,4 +2556,3 @@ msgstr "" | |
#: ../../../CHANGES.rst:1178 | ||
msgid "First public preview release." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,4 +808,3 @@ msgstr "" | |
#: ../../config.rst:760 | ||
msgid "Example usage for both::" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,4 +215,3 @@ msgstr "" | |
#: ../../deploying/fastcgi.rst:233 | ||
msgid "Different python interpreters being used." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,4 +80,3 @@ msgstr "" | |
#: ../../deploying/index.rst:25 | ||
msgid "Self-hosted options" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,4 +413,3 @@ msgid "" | |
"``python_requires=\">= 3.6\"`` in ``setup.py`` to indicate supported " | ||
"versions." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,3 @@ msgid "" | |
"create your own. Read :doc:`/extensiondev` to develop your own Flask " | ||
"extension." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,4 +182,3 @@ msgid "" | |
msgstr "" | ||
"Flask 现在已经安装好了。阅读 :doc:`/quickstart` 或是前往 :doc:`文档概览 </index>` 进一步了解 " | ||
"Flask。" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,4 +111,3 @@ msgid "" | |
"https://palletsprojects.com/p/flask/ if you use it in a medium that " | ||
"supports links." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,4 +139,3 @@ msgid "" | |
"falls back to another application if the creator function returns " | ||
"``None``::" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,4 +168,3 @@ msgid "" | |
"Add in WSGI middlewares when the application is being created if " | ||
"necessary." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,3 @@ msgid "" | |
" of the user in a cookie in a :meth:`~flask.Flask.before_request` " | ||
"callback::" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,4 +82,3 @@ msgid "" | |
"The `Favicon <https://en.wikipedia.org/wiki/Favicon>`_ article on " | ||
"Wikipedia" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
worker翻译为线程似不妥,建议翻为
例程(worker)
以总括进程线程协程,首次使用可附上原词,并参考翻译词汇的讨论结果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.
已将
例程
放到 #12 投票中。顺便一提有相关
worker
译为例程
的例子吗?我是第一次见到这种翻译。