8
8
msgstr ""
9
9
"Project-Id-Version : Flask 2.1.x\n "
10
10
"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 "
12
12
"PO-Revision-Date : YEAR-MO-DA HO:MI+ZONE\n "
13
13
"
Last-Translator :
rosekc <[email protected] >\n "
14
14
"
Language-Team :
LANGUAGE <[email protected] >\n "
@@ -25,18 +25,19 @@ msgstr "使用 ``async`` 和 ``await``"
25
25
msgid ""
26
26
"Routes, error handlers, before request, after request, and teardown "
27
27
"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 "
29
30
"defined with ``async def`` and use ``await``."
30
31
msgstr ""
31
32
"在安装 Flask 时使用 ``async`` 额外后缀(``pip install flask[async]``)后,"
32
33
"包括路由、错误处理、请求前、请求后、清理(teardown)的函数都可以使用协程函数。"
33
34
"这允许视图函数使用 ``async def`` 定义,以及使用 ``await``。"
34
35
35
- #: ../../async-await.rst:20
36
+ #: ../../async-await.rst:21
36
37
msgid "Using ``async`` on Windows on Python 3.8"
37
38
msgstr "在 Windows,Python 3.8 环境下使用 ``async``"
38
39
39
- #: ../../async-await.rst:22
40
+ #: ../../async-await.rst:23
40
41
msgid ""
41
42
"Python 3.8 has a bug related to asyncio on Windows. If you encounter "
42
43
"something like ``ValueError: set_wakeup_fd only works in main thread``, "
@@ -46,11 +47,11 @@ msgstr ""
46
47
"类似 ``ValueError: set_wakeup_fd only works in main thread`` 的信息,"
47
48
"请更新到 Python 3.9。"
48
49
49
- #: ../../async-await.rst:28
50
+ #: ../../async-await.rst:29
50
51
msgid "Performance"
51
52
msgstr "性能"
52
53
53
- #: ../../async-await.rst:30
54
+ #: ../../async-await.rst:31
54
55
msgid ""
55
56
"Async functions require an event loop to run. Flask, as a WSGI "
56
57
"application, uses one worker to handle one request/response cycle. When a"
@@ -61,7 +62,7 @@ msgstr ""
61
62
"请求/响应循环。当请求进入一个异步视图函数时,Flask 将在一个线程中启动一个事件"
62
63
"循环,在这个事件循环中执行视图函数,然后返回结果。"
63
64
64
- #: ../../async-await.rst:35
65
+ #: ../../async-await.rst:36
65
66
msgid ""
66
67
"Each request still ties up one worker, even for async views. The upside "
67
68
"is that you can run async code within a view, for example to make "
@@ -73,7 +74,7 @@ msgstr ""
73
74
"视图函数中可以执行异步代码,例如多个并行的数据库查询,HTTP请求外部API等等。"
74
75
"然而,同一时间应用本身能接受的请求数量不会改变。"
75
76
76
- #: ../../async-await.rst:41
77
+ #: ../../async-await.rst:42
77
78
msgid ""
78
79
"**Async is not inherently faster than sync code.** Async is beneficial "
79
80
"when performing concurrent IO-bound tasks, but will probably not improve "
@@ -85,11 +86,11 @@ msgstr ""
85
86
"则不然。传统的 Flask 视图函数在大多数情况下是合适的选择,而 Flask 对异步的支持让"
86
87
"运行和使用协程代码成为可能,这是以前原生环境无法做到的。"
87
88
88
- #: ../../async-await.rst:49
89
+ #: ../../async-await.rst:50
89
90
msgid "Background tasks"
90
91
msgstr "后台任务"
91
92
92
- #: ../../async-await.rst:51
93
+ #: ../../async-await.rst:52
93
94
msgid ""
94
95
"Async functions will run in an event loop until they complete, at which "
95
96
"stage the event loop will stop. This means any additional spawned tasks "
@@ -101,7 +102,7 @@ msgstr ""
101
102
"这意味着异步函数完成的时候,所有尚未完成的其他衍生任务都将被取消。因此,不能使用"
102
103
"类似 ``asyncio.create_task`` 的方法来创建后台任务。"
103
104
104
- #: ../../async-await.rst:57
105
+ #: ../../async-await.rst:58
105
106
msgid ""
106
107
"If you wish to use background tasks it is best to use a task queue to "
107
108
"trigger background work, rather than spawn tasks in a view function. With"
@@ -115,11 +116,11 @@ msgstr ""
115
116
" :ref:`asgi` 提到的使用 asgiref 中的 WsgiToAsgi 适配器。这种做法与适配器"
116
117
"创建了一个持续运行的事件循环类似。"
117
118
118
- #: ../../async-await.rst:66
119
+ #: ../../async-await.rst:67
119
120
msgid "When to use Quart instead"
120
121
msgstr "何时使用 Quart 作为替代品"
121
122
122
- #: ../../async-await.rst:68
123
+ #: ../../async-await.rst:69
123
124
msgid ""
124
125
"Flask's async support is less performant than async-first frameworks due "
125
126
"to the way it is implemented. If you have a mainly async codebase it "
@@ -133,7 +134,7 @@ msgstr ""
133
134
"的 Flask 重新实现版本(而 Flask 是基于 WSGI 的)。这让多并行请求,长时间运行"
134
135
"的请求,以及 websockets 编程不再需要多个工作进程或线程。"
135
136
136
- #: ../../async-await.rst:75
137
+ #: ../../async-await.rst:76
137
138
msgid ""
138
139
"It has also already been possible to run Flask with Gevent or Eventlet to"
139
140
" get many of the benefits of async request handling. These libraries "
@@ -147,11 +148,11 @@ msgstr ""
147
148
"使用了现代标准 Python 的特性。决定是否应使用 Flask,Quart 或其他工具最终取决于"
148
149
"了解项目的特定需求。"
149
150
150
- #: ../../async-await.rst:87
151
+ #: ../../async-await.rst:88
151
152
msgid "Extensions"
152
153
msgstr "扩展"
153
154
154
- #: ../../async-await.rst:89
155
+ #: ../../async-await.rst:90
155
156
msgid ""
156
157
"Flask extensions predating Flask's async support do not expect async "
157
158
"views. If they provide decorators to add functionality to views, those "
@@ -165,7 +166,7 @@ msgstr ""
165
166
"异步可等待(awaitable)的,可能在异步视图函数上不能正常运行。扩展提供的其他函数或许"
166
167
"同样不是异步可等待的,在异步视图函数调用的时候大概会阻塞。"
167
168
168
- #: ../../async-await.rst:95
169
+ #: ../../async-await.rst:96
169
170
msgid ""
170
171
"Extension authors can support async functions by utilising the "
171
172
":meth:`flask.Flask.ensure_sync` method. For example, if the extension "
@@ -175,22 +176,33 @@ msgstr ""
175
176
"扩展作者可以通过使用 :meth:`flask.Flask.ensure_sync` 方法来支持异步函数。"
176
177
"举例来说,如果扩展提供了一个视图函数装饰器,使用 ``ensure_sync`` 调用被包裹的函数。"
177
178
178
- #: ../../async-await.rst:110
179
+ #: ../../async-await.rst:111
179
180
msgid ""
180
181
"Check the changelog of the extension you want to use to see if they've "
181
182
"implemented async support, or make a feature request or PR to them."
182
183
msgstr ""
183
184
"检查扩展的更新记录,查看是否实现了异步支持。如果没有可以向他们提交 PR。"
184
185
185
- #: ../../async-await.rst:115
186
+ #: ../../async-await.rst:116
186
187
msgid "Other event loops"
187
188
msgstr "其他事件循环"
188
189
189
- #: ../../async-await.rst:117
190
+ #: ../../async-await.rst:118
190
191
msgid ""
191
192
"At the moment Flask only supports :mod:`asyncio`. It's possible to "
192
193
"override :meth:`flask.Flask.ensure_sync` to change how async functions "
193
194
"are wrapped to use a different library."
194
195
msgstr ""
196
+
195
197
"当前 Flask 只支持 :mod:`asyncio`。覆盖 :meth:`flask.Flask.ensure_sync` "
196
198
"可以修改包裹异步函数的实现,以使用其他库。"
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