-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathasyncio-threading.po
More file actions
211 lines (190 loc) · 7.27 KB
/
Copy pathasyncio-threading.po
File metadata and controls
211 lines (190 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.15\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-09-03 17:25+0000\n"
"PO-Revision-Date: 2026-06-11 17:36+0000\n"
"Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/"
"ja/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ja\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../library/asyncio-threading.rst:6
msgid "asyncio and free-threaded Python"
msgstr ""
#: ../../library/asyncio-threading.rst:8
msgid ""
"asyncio uses an event loop as a scheduler to enable highly efficient "
"concurrency by switching between tasks to allow non-blocking I/O operations. "
"This results in better performance for I/O-bound use cases. It also allows "
"off-loading CPU-bound work to a thread or process pool, but that is still "
"limited by the :term:`global interpreter lock` in CPython."
msgstr ""
#: ../../library/asyncio-threading.rst:15
msgid ""
"However, in :ref:`free-threaded Python <freethreading-python-howto>`, the "
"GIL is disabled and Python can run true multi-threaded code. This means that "
"asyncio can now take advantage of multiple CPU cores without the limitations "
"imposed by the GIL."
msgstr ""
#: ../../library/asyncio-threading.rst:20
msgid ""
"Since Python 3.14, asyncio has first-class support for free-threaded Python, "
"and the implementation of asyncio is safe to use in a multi-threaded "
"environment."
msgstr ""
#: ../../library/asyncio-threading.rst:24
msgid ""
"A single event loop on one core can handle many connections concurrently, "
"but the Python code that runs to handle each one still executes serially. "
"Once requests involve a non-trivial amount of per-request computation, that "
"handling becomes the bottleneck, and a single core can no longer keep up. "
"Combining asyncio with threads is most useful here: by running an event loop "
"per thread, the handling of different requests can run in parallel across "
"multiple CPU cores. It is also useful when you need to run blocking or CPU-"
"bound code from an asyncio application."
msgstr ""
#: ../../library/asyncio-threading.rst:37
msgid ""
"`Scaling asyncio on Free-Threaded Python <https://labs.quansight.org/blog/"
"scaling-asyncio-on-free-threaded-python>`__, a blog post by Kumar Aditya "
"which explains the internal changes that make asyncio safe and efficient "
"under free-threaded Python, together with benchmarks of the resulting "
"improvements."
msgstr ""
#: ../../library/asyncio-threading.rst:45
msgid "Thread safety considerations"
msgstr ""
#: ../../library/asyncio-threading.rst:47
msgid ""
"While asyncio is designed to be thread-safe in a free-threaded Python "
"environment, there are still some considerations to keep in mind when using "
"asyncio with threads:"
msgstr ""
#: ../../library/asyncio-threading.rst:51
msgid ""
"**Event loop**: Each thread should have its own event loop which should not "
"be shared across threads. This ensures that the event loop can manage its "
"own tasks and callbacks without interference from other threads."
msgstr ""
#: ../../library/asyncio-threading.rst:56
msgid ""
"**Task management**: Tasks and futures created in one thread should not be "
"awaited or manipulated from another thread."
msgstr ""
#: ../../library/asyncio-threading.rst:59
msgid ""
"**Thread-safe APIs**: When interacting with asyncio from multiple threads, "
"it's important to use thread-safe APIs provided by asyncio, such as :func:"
"`asyncio.run_coroutine_threadsafe` for submitting coroutines to an event "
"loop from another thread. If you need to call a callback from a different "
"thread, you can use :meth:`loop.call_soon_threadsafe` to schedule it safely."
msgstr ""
#: ../../library/asyncio-threading.rst:66
msgid ""
"**Synchronization**: The synchronization primitives provided by asyncio "
"(like :class:`asyncio.Lock` and :class:`asyncio.Event`) are not designed to "
"be used across threads. If you need to synchronize between threads, you "
"should use the synchronization primitives from the :mod:`threading` module "
"instead."
msgstr ""
#: ../../library/asyncio-threading.rst:74
msgid "Using asyncio with threads"
msgstr ""
#: ../../library/asyncio-threading.rst:76
msgid ""
"asyncio supports running one event loop per thread, which allows you to take "
"advantage of multiple CPU cores in a free-threaded Python environment. Each "
"thread can run its own event loop, and tasks can be scheduled on those loops "
"independently."
msgstr ""
#: ../../library/asyncio-threading.rst:81
msgid "Here's an example of how to use asyncio with threads::"
msgstr ""
#: ../../library/asyncio-threading.rst:83
msgid ""
"import asyncio\n"
"import threading\n"
"\n"
"async def worker(name: str) -> None:\n"
" print(f\"Worker {name} starting\")\n"
" await asyncio.sleep(1)\n"
" print(f\"Worker {name} done\")\n"
"\n"
"def run_loop(name: str) -> None:\n"
" asyncio.run(worker(name))\n"
"\n"
"threads = [\n"
" threading.Thread(target=run_loop, args=(f\"T{i}\",))\n"
" for i in range(4)\n"
"]\n"
"for t in threads:\n"
" t.start()\n"
"for t in threads:\n"
" t.join()"
msgstr ""
#: ../../library/asyncio-threading.rst:103
msgid ""
"In this example, each thread creates its own event loop with :func:`asyncio."
"run` and runs a coroutine on it. The threads execute concurrently, and in a "
"free-threaded build they can run on separate CPU cores in parallel."
msgstr ""
#: ../../library/asyncio-threading.rst:110
msgid "Producer/consumer across threads"
msgstr ""
#: ../../library/asyncio-threading.rst:112
msgid ""
"When a regular (non-asyncio) thread needs to hand work to an asyncio event "
"loop running in another thread, use a thread-safe primitive such as :class:"
"`queue.Queue` rather than :class:`asyncio.Queue`, which is only safe within "
"a single event loop.::"
msgstr ""
#: ../../library/asyncio-threading.rst:117
msgid ""
"import asyncio\n"
"import queue\n"
"import threading\n"
"\n"
"def producer(q: queue.Queue[int]) -> None:\n"
" for i in range(5):\n"
" print(f\"Producing {i}\")\n"
" q.put(i)\n"
" q.shutdown()\n"
"\n"
"async def consumer(q: queue.Queue[int]) -> None:\n"
" while True:\n"
" try:\n"
" item = q.get_nowait()\n"
" except queue.Empty:\n"
" await asyncio.sleep(0.1)\n"
" continue\n"
" except queue.ShutDown:\n"
" break\n"
" print(f\"Consumed {item}\")\n"
" await asyncio.sleep(item)\n"
"\n"
"q: queue.Queue[int] = queue.Queue()\n"
"consumer_thread = threading.Thread(\n"
" target=lambda: asyncio.run(consumer(q))\n"
")\n"
"consumer_thread.start()\n"
"producer(q)\n"
"consumer_thread.join()"
msgstr ""
#: ../../library/asyncio-threading.rst:147
msgid ""
"The producer runs on the main thread while the consumer runs inside an event "
"loop on its own thread, yet they communicate safely through ``queue.Queue``. "
"When the queue is empty the consumer sleeps briefly and tries again. When "
"the producer is done it calls :meth:`~queue.Queue.shutdown`, which causes "
"subsequent :meth:`~queue.Queue.get_nowait` calls to raise :exc:`queue."
"ShutDown` so the consumer can exit cleanly."
msgstr ""