-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathasyncio-threading.po
More file actions
180 lines (159 loc) · 14.6 KB
/
Copy pathasyncio-threading.po
File metadata and controls
180 lines (159 loc) · 14.6 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
# Persian translations for Python package.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# Automatically generated, 2026.
#
# Translators:
# Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-09-16 12:56+0000\n"
"PO-Revision-Date: 2026-09-15 12:28+0330\n"
"Last-Translator: Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026\n"
"Language-Team: none\n"
"Language: fa\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.6\n"
msgid "asyncio and free-threaded Python"
msgstr "asyncio و پایتون نخآزاد"
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 "asyncio از یک حلقه رویداد بهعنوان زمانبند استفاده میکند تا با جابهجایی بین وظایف و امکانپذیر ساختن عملیات ورودی/خروجی غیرمسدودکننده، همروندی بسیار کارآمدی را فراهم کند. این امر باعث عملکرد بهتر در موارد استفاده محدود به ورودی/خروجی میشود. همچنین امکان واگذاری کارهای محدود به CPU به یک استخر نخ یا فرایند را فراهم میکند، اما این کار در CPython همچنان محدود به :term:`قفل سراسری مفسر <global interpreter lock>` است."
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 "با این حال، در :ref:`free-threaded Python <freethreading-python-howto>`، GIL غیرفعال است و پایتون میتواند کد چندنخی واقعی را اجرا کند. این بدان معناست که asyncio اکنون میتواند از چندین هسته CPU بدون محدودیتهای اعمالشده توسط GIL بهره ببرد."
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 "از پایتون ۳.۱۴، asyncio پشتیبانی درجهیک از پایتون نخآزاد دارد و پیادهسازی asyncio برای استفاده در محیط چندنخی ایمن است."
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 "یک حلقه رویداد واحد روی یک هسته میتواند اتصالهای زیادی را بهطور همروند مدیریت کند، اما کد پایتونی که برای مدیریت هر یک اجرا میشود همچنان بهصورت متوالی اجرا میشود. هنگامی که درخواستها شامل مقدار قابلتوجهی محاسبه بهازای هر درخواست شوند، مدیریت آنها به گلوگاه تبدیل میشود و یک هسته دیگر نمیتواند پاسخگو باشد. ترکیب asyncio با نخها در اینجا بیشترین کاربرد را دارد: با اجرای یک حلقه رویداد بهازای هر نخ، مدیریت درخواستهای مختلف میتواند بهصورت موازی روی چندین هسته CPU اجرا شود. همچنین زمانی که نیاز دارید کد مسدودکننده یا محدود به CPU را از یک برنامه asyncio اجرا کنید، مفید است."
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 "`Scaling asyncio on Free-Threaded Python <https://labs.quansight.org/blog/scaling-asyncio-on-free-threaded-python>`__، یک پست وبگزارشی از Kumar Aditya که تغییرات داخلیای را توضیح میدهد که باعث ایمن و کارآمد شدن asyncio در پایتون نخآزادی (Free-Threaded Python) میشوند، بههمراه بنچمارکهایی از بهبودهای حاصل."
msgid "Thread safety considerations"
msgstr "ملاحظات ایمنی نخها"
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 "هرچند asyncio بهگونهای طراحی شده است که در یک محیط پایتون نخآزاد (free-threaded) امن از نظر نخها (thread-safe) باشد، اما همچنان هنگام استفاده از asyncio با نخها ملاحظاتی وجود دارد که باید آنها را در نظر داشته باشید:"
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 "**حلقه رویداد**: هر نخ باید حلقه رویداد مخصوص به خود را داشته باشد که نباید بین نخها به اشتراک گذاشته شود. این امر تضمین میکند که حلقه رویداد میتواند وظایف و کالبکهای خود را بدون تداخل از سوی نخهای دیگر مدیریت کند."
msgid "**Task management**: Tasks and futures created in one thread should not be awaited or manipulated from another thread."
msgstr "**مدیریت وظیفه**: وظایف و آیندهنماها (futures) ایجادشده در یک نخ نباید از نخی دیگر await شوند یا دستکاری شوند."
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 "**APIهای ایمن برای نخ**: هنگام تعامل با asyncio از چندین نخ، مهم است که از APIهای ایمن برای نخ ارائهشده توسط asyncio استفاده کنید، مانند :func:`asyncio.run_coroutine_threadsafe` برای ارسال همروالها به یک حلقه رویداد از یک نخ دیگر. اگر نیاز دارید یک کالبک را از یک نخ متفاوت فراخوانی کنید، میتوانید از :meth:`loop.call_soon_threadsafe` برای زمانبندی ایمن آن استفاده کنید."
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 "**همگامسازی**: ابزارهای همگامسازی ارائهشده توسط asyncio (مانند :class:`asyncio.Lock` و :class:`asyncio.Event`) برای استفاده در میان نخها طراحی نشدهاند. اگر نیاز به همگامسازی بین نخها دارید، باید بهجای آن از ابزارهای همگامسازی ماژول :mod:`threading` استفاده کنید."
msgid "Using asyncio with threads"
msgstr "استفاده از asyncio با نخها"
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 "asyncio از اجرای یک حلقه رویداد به ازای هر نخ پشتیبانی میکند، که به شما امکان میدهد در یک محیط پایتون نخآزادی از چندین هسته CPU بهره ببرید. هر نخ میتواند حلقه رویداد خود را اجرا کند، و وظایف میتوانند بهطور مستقل روی آن حلقهها زمانبندی شوند."
msgid "Here's an example of how to use asyncio with threads::"
msgstr "در اینجا مثالی از نحوهی استفاده از asyncio با نخها آمده است::"
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 ""
"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()"
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 "در این مثال، هر نخ حلقه رویداد خود را با :func:`asyncio.run` ایجاد میکند و یک همروال را روی آن اجرا میکند. نخها بهطور همزمان اجرا میشوند و در یک ساخت نخآزاد (free-threaded build) میتوانند روی هستههای جداگانهی CPU بهصورت موازی اجرا شوند."
msgid "Producer/consumer across threads"
msgstr "تولیدکننده/مصرفکننده بین نخها"
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 "هنگامی که یک نخ معمولی (غیر asyncio) نیاز دارد کاری را به یک حلقهی رویداد asyncio که در نخ دیگری اجرا میشود بسپارد، از یک سازوکار اولیهی ایمن برای نخ مانند :class:`queue.Queue` استفاده کنید، نه از :class:`asyncio.Queue`، که فقط درون یک حلقهی رویداد واحد ایمن است.::"
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 ""
"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()"
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 "تولیدکننده روی نخ اصلی اجرا میشود، در حالی که مصرفکننده درون یک حلقه رویداد روی نخ اختصاصی خود اجرا میشود، با این حال آنها بهصورت امن از طریق ``queue.Queue`` با یکدیگر ارتباط برقرار میکنند. وقتی صف خالی است، مصرفکننده برای مدت کوتاهی متوقف میشود و دوباره تلاش میکند. هنگامی که تولیدکننده کارش را تمام کرد، :meth:`~queue.Queue.shutdown` را فراخوانی میکند، که باعث میشود فراخوانیهای بعدی :meth:`~queue.Queue.get_nowait` استثنا :exc:`queue.ShutDown` را پرتاب کنند تا مصرفکننده بتواند بهصورت تمیز خارج شود."