generated from flaskcwg/translation-template
-
Notifications
You must be signed in to change notification settings - Fork 21
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 3 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 hidden or 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 hidden or 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,27 @@ 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)的函数都可以使用协程函数。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"这允许视图函数使用 ``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。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../async-await.rst:29 | ||
msgid "Performance" | ||
msgstr "" | ||
msgstr "性能" | ||
|
||
#: ../../async-await.rst:31 | ||
msgid "" | ||
|
@@ -52,6 +58,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 使用一个线程去处理" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. worker翻译为线程似不妥,建议翻为 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已将 顺便一提有相关 |
||
"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件" | ||
"循环,在这个事件循环中执行视图函数,然后返回结果。" | ||
|
||
#: ../../async-await.rst:36 | ||
msgid "" | ||
|
@@ -61,6 +70,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 +82,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 +98,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 +111,14 @@ msgid "" | |
":ref:`asgi`. This works as the adapter creates an event loop that runs " | ||
"continually." | ||
msgstr "" | ||
"要使用后台任务,最好的方法就是使用任务队列去激活后台任务,而不是在视图函数中" | ||
"创建。考虑到这点,使用 ASGI 服务器来为 Flask 提供服务来创建后台任务,然后如" | ||
" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这种做法与适配器" | ||
"创建了一个持续运行的事件循环类似。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../async-await.rst:67 | ||
msgid "When to use Quart instead" | ||
msgstr "" | ||
msgstr "何时使用 Quart 作为替代品" | ||
|
||
#: ../../async-await.rst:69 | ||
msgid "" | ||
|
@@ -107,6 +129,10 @@ msgid "" | |
"handle many concurrent requests, long running requests, and websockets " | ||
"without requiring multiple worker processes or threads." | ||
msgstr "" | ||
"基于实现上的不同,Flask 的异步支持的性能比异步优先的框架会稍低。如果已经拥有" | ||
"一个以异步为主的代码库,考虑使用 `Quart`_ 是明智的选择。Quart 是一个基于 `ASGI`_ " | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行" | ||
"的请求,以及 websockets 编程不再需要多个工作进程或线程。" | ||
|
||
#: ../../async-await.rst:76 | ||
msgid "" | ||
|
@@ -117,10 +143,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 来得到使用异步请求处理的好处。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"这些库通过为底层 Python 库打补丁的方式实现,而 ``async``/``await`` 与 ASGI" | ||
"使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于" | ||
"了解项目的特定需求。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../async-await.rst:88 | ||
msgid "Extensions" | ||
msgstr "" | ||
msgstr "扩展" | ||
|
||
#: ../../async-await.rst:90 | ||
msgid "" | ||
|
@@ -131,6 +161,10 @@ msgid "" | |
"awaitable either and will probably be blocking if called within an async " | ||
"view." | ||
msgstr "" | ||
"Flask 扩展系统的实现先于 Flask 异步支持,所以并不会假设视图函数是异步的。如果扩展" | ||
"提供了对视图函数的有附加功能的装饰器,这些装饰器因为不会异步等待(await)函数运行或者不是" | ||
"异步可等待(awaitable)的,可能在异步视图函数上不能正常运行。扩展提供的其他函数或许" | ||
"同样不是异步可等待的,在异步视图函数调用的时候大概会阻塞。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../async-await.rst:96 | ||
msgid "" | ||
|
@@ -139,23 +173,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` " | ||
"可以修改包裹异步函数的实现,以使用其他库。" | ||
rosekc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#~ msgid "" | ||
#~ "Routes, error handlers, before request, " | ||
|
@@ -166,4 +205,3 @@ msgstr "" | |
#~ " allows views to be defined with " | ||
#~ "``async def`` and use ``await``." | ||
#~ msgstr "" | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.