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