@@ -10,7 +10,7 @@ msgstr ""
10
10
"Report-Msgid-Bugs-To : \n "
11
11
"POT-Creation-Date : 2021-05-25 19:31+0800\n "
12
12
"PO-Revision-Date : YEAR-MO-DA HO:MI+ZONE\n "
13
- "Last-Translator : FULL NAME <EMAIL@ADDRESS >\n "
13
+ "
Last-Translator :
rosekc <[email protected] >\n"
14
14
"
Language-Team :
LANGUAGE <[email protected] >\n "
15
15
"MIME-Version : 1.0\n "
16
16
"Content-Type : text/plain; charset=utf-8\n "
@@ -19,7 +19,7 @@ msgstr ""
19
19
20
20
#: ../../async-await.rst:4
21
21
msgid "Using ``async`` and ``await``"
22
- msgstr ""
22
+ msgstr "使用 ``async`` 和 ``await`` "
23
23
24
24
#: ../../async-await.rst:8
25
25
msgid ""
@@ -28,21 +28,27 @@ msgid ""
28
28
"``async`` extra (``pip install flask[async]``). This allows views to be "
29
29
"defined with ``async def`` and use ``await``."
30
30
msgstr ""
31
+ "在安装 Flask 时使用 ``async`` 额外后缀(``pip install flask[async]``)后,"
32
+ "包括路由、错误处理、请求前、请求后、清理(teardown)的函数都可以使用协程函数。"
33
+ "这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。"
31
34
32
35
#: ../../async-await.rst:20
33
36
msgid "Using ``async`` on Windows on Python 3.8"
34
- msgstr ""
37
+ msgstr "在 Windows,Python 3.8 环境下使用 ``async`` "
35
38
36
39
#: ../../async-await.rst:22
37
40
msgid ""
38
41
"Python 3.8 has a bug related to asyncio on Windows. If you encounter "
39
42
"something like ``ValueError: set_wakeup_fd only works in main thread``, "
40
43
"please upgrade to Python 3.9."
41
44
msgstr ""
45
+ "在 Windows,Python 3.8 环境下存在一个与 asyncio 相关的 bug。如果遇到"
46
+ "类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息,"
47
+ "请更新到 Python 3.9。"
42
48
43
49
#: ../../async-await.rst:28
44
50
msgid "Performance"
45
- msgstr ""
51
+ msgstr "性能 "
46
52
47
53
#: ../../async-await.rst:30
48
54
msgid ""
@@ -51,6 +57,9 @@ msgid ""
51
57
" request comes in to an async view, Flask will start an event loop in a "
52
58
"thread, run the view function there, then return the result."
53
59
msgstr ""
60
+ "异步函数需要一个事件循环来执行。作为一个 WSGI 应用,Flask 使用一个线程去处理"
61
+ "请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件"
62
+ "循环,在这个事件循环中执行视图函数,然后返回结果。"
54
63
55
64
#: ../../async-await.rst:35
56
65
msgid ""
@@ -60,6 +69,9 @@ msgid ""
60
69
"etc. However, the number of requests your application can handle at one "
61
70
"time will remain the same."
62
71
msgstr ""
72
+ "即使使用异步视图函数,每一个请求依然与一个线程绑定在一起。这样设计的好处是让"
73
+ "视图函数中可以执行异步代码,例如多个并行的数据库查询,HTTP请求外部API等等。"
74
+ "然而,同一时间应用本身能接受的请求数量不会改变。"
63
75
64
76
#: ../../async-await.rst:41
65
77
msgid ""
@@ -69,10 +81,13 @@ msgid ""
69
81
"most use cases, but Flask's async support enables writing and using code "
70
82
"that wasn't possible natively before."
71
83
msgstr ""
84
+ "**异步并不一定比同步代码快。** 异步的优势是在IO密集任务上,但是在CPU密集任务上"
85
+ "则不然。传统的 Flask 视图函数在大多数情况下是合适的选择,而 Flask 对异步的支持让"
86
+ "运行和使用协程代码成为可能,这是以前原生环境无法做到的。"
72
87
73
88
#: ../../async-await.rst:49
74
89
msgid "Background tasks"
75
- msgstr ""
90
+ msgstr "后台任务 "
76
91
77
92
#: ../../async-await.rst:51
78
93
msgid ""
@@ -82,6 +97,9 @@ msgid ""
82
97
"cancelled. Therefore you cannot spawn background tasks, for example via "
83
98
"``asyncio.create_task``."
84
99
msgstr ""
100
+ "异步函数在其执行完成前,都一个事件循环中运行。当异步函数完成时,事件循环也将停止。"
101
+ "这意味着异步函数完成的时候,所有尚未完成的其他衍生任务都将被取消。因此,不能使用"
102
+ "类似 ``asyncio.create_task`` 的方法来创建后台任务。"
85
103
86
104
#: ../../async-await.rst:57
87
105
msgid ""
@@ -92,10 +110,14 @@ msgid ""
92
110
":ref:`asgi`. This works as the adapter creates an event loop that runs "
93
111
"continually."
94
112
msgstr ""
113
+ "要使用后台任务,最好的方法就是使用任务队列去激活后台任务,而不是在视图函数中"
114
+ "创建。考虑到这点,使用 ASGI 服务器来为 Flask 提供服务来创建后台任务,然后如"
115
+ " :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这种做法与适配器"
116
+ "创建了一个持续运行的事件循环类似。"
95
117
96
118
#: ../../async-await.rst:66
97
119
msgid "When to use Quart instead"
98
- msgstr ""
120
+ msgstr "何时使用 Quart 作为替代品 "
99
121
100
122
#: ../../async-await.rst:68
101
123
msgid ""
@@ -106,6 +128,10 @@ msgid ""
106
128
"handle many concurrent requests, long running requests, and websockets "
107
129
"without requiring multiple worker processes or threads."
108
130
msgstr ""
131
+ "基于实现上的不同,Flask 的异步支持的性能比异步优先的框架会稍低。如果已经拥有"
132
+ "一个以异步为主的代码库,考虑使用 `Quart`_ 是明智的选择。Quart 是一个基于 `ASGI`_ "
133
+ "的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行"
134
+ "的请求,以及 websockets 编程不再需要多个工作进程或线程。"
109
135
110
136
#: ../../async-await.rst:75
111
137
msgid ""
@@ -116,10 +142,14 @@ msgid ""
116
142
"whether you should use Flask, Quart, or something else is ultimately up "
117
143
"to understanding the specific needs of your project."
118
144
msgstr ""
145
+ "当前已经可以使用 Gevent 或 Eventlet 运行 Flask 来得到使用异步请求处理的好处。"
146
+ "这些库通过为底层 Python 库打补丁的方式实现,而 ``async``/``await`` 与 ASGI"
147
+ "使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于"
148
+ "了解项目的特定需求。"
119
149
120
150
#: ../../async-await.rst:87
121
151
msgid "Extensions"
122
- msgstr ""
152
+ msgstr "扩展 "
123
153
124
154
#: ../../async-await.rst:89
125
155
msgid ""
@@ -130,6 +160,10 @@ msgid ""
130
160
"awaitable either and will probably be blocking if called within an async "
131
161
"view."
132
162
msgstr ""
163
+ "Flask 扩展系统的实现先于 Flask 异步支持,所以并不会假设视图函数是异步的。如果扩展"
164
+ "提供了对视图函数的有附加功能的装饰器,这些装饰器因为不会异步等待(await)函数运行或者不是"
165
+ "异步可等待(awaitable)的,可能在异步视图函数上不能正常运行。扩展提供的其他函数或许"
166
+ "同样不是异步可等待的,在异步视图函数调用的时候大概会阻塞。"
133
167
134
168
#: ../../async-await.rst:95
135
169
msgid ""
@@ -138,21 +172,25 @@ msgid ""
138
172
"provides a view function decorator add ``ensure_sync`` before calling the"
139
173
" decorated function,"
140
174
msgstr ""
175
+ "扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。"
176
+ "举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。"
141
177
142
178
#: ../../async-await.rst:110
143
179
msgid ""
144
180
"Check the changelog of the extension you want to use to see if they've "
145
181
"implemented async support, or make a feature request or PR to them."
146
182
msgstr ""
183
+ "检查扩展的更新记录,查看是否实现了异步支持。如果没有可以向他们提交 PR。"
147
184
148
185
#: ../../async-await.rst:115
149
186
msgid "Other event loops"
150
- msgstr ""
187
+ msgstr "其他事件循环 "
151
188
152
189
#: ../../async-await.rst:117
153
190
msgid ""
154
191
"At the moment Flask only supports :mod:`asyncio`. It's possible to "
155
192
"override :meth:`flask.Flask.ensure_sync` to change how async functions "
156
193
"are wrapped to use a different library."
157
194
msgstr ""
158
-
195
+ "当前 Flask 只支持 :mod:`asyncio`。覆盖 :meth:`flask.Flask.ensure_sync` "
196
+ "可以修改包裹异步函数的实现,以使用其他库。"
0 commit comments