88msgstr ""
99"Project-Id-Version : Flask 2.1.x\n "
1010"Report-Msgid-Bugs-To : \n "
11- "POT-Creation-Date : 2021-05-25 19:31+0800 \n "
11+ "POT-Creation-Date : 2021-05-30 19:27+0000 \n "
1212"PO-Revision-Date : YEAR-MO-DA HO:MI+ZONE\n "
1313"
Last-Translator :
rosekc <[email protected] >\n "
1414"
Language-Team :
LANGUAGE <[email protected] >\n "
@@ -25,18 +25,19 @@ msgstr "使用 ``async`` 和 ``await``"
2525msgid ""
2626"Routes, error handlers, before request, after request, and teardown "
2727"functions can all be coroutine functions if Flask is installed with the "
28- "``async`` extra (``pip install flask[async]``). This allows views to be "
28+ "``async`` extra (``pip install flask[async]``). It requires Python 3.7+ "
29+ "where ``contextvars.ContextVar`` is available. This allows views to be "
2930"defined with ``async def`` and use ``await``."
3031msgstr ""
3132"在安装 Flask 时使用 ``async`` 额外后缀(``pip install flask[async]``)后,"
3233"包括路由、错误处理、请求前、请求后、清理(teardown)的函数都可以使用协程函数。"
3334"这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。"
3435
35- #: ../../async-await.rst:20
36+ #: ../../async-await.rst:21
3637msgid "Using ``async`` on Windows on Python 3.8"
3738msgstr "在 Windows,Python 3.8 环境下使用 ``async``"
3839
39- #: ../../async-await.rst:22
40+ #: ../../async-await.rst:23
4041msgid ""
4142"Python 3.8 has a bug related to asyncio on Windows. If you encounter "
4243"something like ``ValueError: set_wakeup_fd only works in main thread``, "
@@ -46,11 +47,11 @@ msgstr ""
4647"类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息,"
4748"请更新到 Python 3.9。"
4849
49- #: ../../async-await.rst:28
50+ #: ../../async-await.rst:29
5051msgid "Performance"
5152msgstr "性能"
5253
53- #: ../../async-await.rst:30
54+ #: ../../async-await.rst:31
5455msgid ""
5556"Async functions require an event loop to run. Flask, as a WSGI "
5657"application, uses one worker to handle one request/response cycle. When a"
@@ -61,7 +62,7 @@ msgstr ""
6162"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件"
6263"循环,在这个事件循环中执行视图函数,然后返回结果。"
6364
64- #: ../../async-await.rst:35
65+ #: ../../async-await.rst:36
6566msgid ""
6667"Each request still ties up one worker, even for async views. The upside "
6768"is that you can run async code within a view, for example to make "
@@ -73,7 +74,7 @@ msgstr ""
7374"视图函数中可以执行异步代码,例如多个并行的数据库查询,HTTP请求外部API等等。"
7475"然而,同一时间应用本身能接受的请求数量不会改变。"
7576
76- #: ../../async-await.rst:41
77+ #: ../../async-await.rst:42
7778msgid ""
7879"**Async is not inherently faster than sync code.** Async is beneficial "
7980"when performing concurrent IO-bound tasks, but will probably not improve "
@@ -85,11 +86,11 @@ msgstr ""
8586"则不然。传统的 Flask 视图函数在大多数情况下是合适的选择,而 Flask 对异步的支持让"
8687"运行和使用协程代码成为可能,这是以前原生环境无法做到的。"
8788
88- #: ../../async-await.rst:49
89+ #: ../../async-await.rst:50
8990msgid "Background tasks"
9091msgstr "后台任务"
9192
92- #: ../../async-await.rst:51
93+ #: ../../async-await.rst:52
9394msgid ""
9495"Async functions will run in an event loop until they complete, at which "
9596"stage the event loop will stop. This means any additional spawned tasks "
@@ -101,7 +102,7 @@ msgstr ""
101102"这意味着异步函数完成的时候,所有尚未完成的其他衍生任务都将被取消。因此,不能使用"
102103"类似 ``asyncio.create_task`` 的方法来创建后台任务。"
103104
104- #: ../../async-await.rst:57
105+ #: ../../async-await.rst:58
105106msgid ""
106107"If you wish to use background tasks it is best to use a task queue to "
107108"trigger background work, rather than spawn tasks in a view function. With"
@@ -115,11 +116,11 @@ msgstr ""
115116" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这种做法与适配器"
116117"创建了一个持续运行的事件循环类似。"
117118
118- #: ../../async-await.rst:66
119+ #: ../../async-await.rst:67
119120msgid "When to use Quart instead"
120121msgstr "何时使用 Quart 作为替代品"
121122
122- #: ../../async-await.rst:68
123+ #: ../../async-await.rst:69
123124msgid ""
124125"Flask's async support is less performant than async-first frameworks due "
125126"to the way it is implemented. If you have a mainly async codebase it "
@@ -133,7 +134,7 @@ msgstr ""
133134"的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行"
134135"的请求,以及 websockets 编程不再需要多个工作进程或线程。"
135136
136- #: ../../async-await.rst:75
137+ #: ../../async-await.rst:76
137138msgid ""
138139"It has also already been possible to run Flask with Gevent or Eventlet to"
139140" get many of the benefits of async request handling. These libraries "
@@ -147,11 +148,11 @@ msgstr ""
147148"使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于"
148149"了解项目的特定需求。"
149150
150- #: ../../async-await.rst:87
151+ #: ../../async-await.rst:88
151152msgid "Extensions"
152153msgstr "扩展"
153154
154- #: ../../async-await.rst:89
155+ #: ../../async-await.rst:90
155156msgid ""
156157"Flask extensions predating Flask's async support do not expect async "
157158"views. If they provide decorators to add functionality to views, those "
@@ -165,7 +166,7 @@ msgstr ""
165166"异步可等待(awaitable)的,可能在异步视图函数上不能正常运行。扩展提供的其他函数或许"
166167"同样不是异步可等待的,在异步视图函数调用的时候大概会阻塞。"
167168
168- #: ../../async-await.rst:95
169+ #: ../../async-await.rst:96
169170msgid ""
170171"Extension authors can support async functions by utilising the "
171172":meth:`flask.Flask.ensure_sync` method. For example, if the extension "
@@ -175,22 +176,33 @@ msgstr ""
175176"扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。"
176177"举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。"
177178
178- #: ../../async-await.rst:110
179+ #: ../../async-await.rst:111
179180msgid ""
180181"Check the changelog of the extension you want to use to see if they've "
181182"implemented async support, or make a feature request or PR to them."
182183msgstr ""
183184"检查扩展的更新记录,查看是否实现了异步支持。如果没有可以向他们提交 PR。"
184185
185- #: ../../async-await.rst:115
186+ #: ../../async-await.rst:116
186187msgid "Other event loops"
187188msgstr "其他事件循环"
188189
189- #: ../../async-await.rst:117
190+ #: ../../async-await.rst:118
190191msgid ""
191192"At the moment Flask only supports :mod:`asyncio`. It's possible to "
192193"override :meth:`flask.Flask.ensure_sync` to change how async functions "
193194"are wrapped to use a different library."
194195msgstr ""
196+
195197"当前 Flask 只支持 :mod:`asyncio`。覆盖 :meth:`flask.Flask.ensure_sync` "
196198"可以修改包裹异步函数的实现,以使用其他库。"
199+
200+ #~ msgid ""
201+ #~ "Routes, error handlers, before request, "
202+ #~ "after request, and teardown functions "
203+ #~ "can all be coroutine functions if "
204+ #~ "Flask is installed with the ``async``"
205+ #~ " extra (``pip install flask[async]``). This"
206+ #~ " allows views to be defined with "
207+ #~ "``async def`` and use ``await``."
208+ #~ msgstr ""
0 commit comments