15
15
# ww song <sww4718168@gmail.com>, 2022
16
16
# Dai Xu <daixu61@hotmail.com>, 2022
17
17
# ProgramRipper, 2023
18
- # Freesand Leo <yuqinju@163.com>, 2025
19
18
# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
19
+ # Freesand Leo <yuqinju@163.com>, 2025
20
20
#
21
21
#, fuzzy
22
22
msgid ""
@@ -25,7 +25,7 @@ msgstr ""
25
25
"Report-Msgid-Bugs-To :\n "
26
26
"POT-Creation-Date :2025-05-16 14:19+0000\n "
27
27
"PO-Revision-Date :2021-06-28 01:15+0000\n "
28
- "Last-Translator :Rafael Fontenelle <rffontenelle@gmail .com>, 2025\n "
28
+ "Last-Translator :Freesand Leo <yuqinju@163 .com>, 2025\n "
29
29
"Language-Team :Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
30
30
"MIME-Version :1.0\n "
31
31
"Content-Type :text/plain; charset=UTF-8\n "
@@ -72,13 +72,19 @@ msgid ""
72
72
"bound, such as file operations or making network requests, where much of the"
73
73
" time is spent waiting for external resources."
74
74
msgstr ""
75
+ ":mod:`!threading` 模块提供了一种在单个进程内部并发地运行多个 `线程 "
76
+ "<https://en.wikipedia.org/wiki/Thread_(computing)>`_ (从进程分出的更小单位) 的方式。 "
77
+ "它允许创建和管理线程,以便能够平行地执行多个任务,并共享内存空间。 线程特别适用于 I/O "
78
+ "密集型的任务,如文件操作或发送网络请求,在此类任务中大部分时间都会消耗于等待外部资源。"
75
79
76
80
#: ../../library/threading.rst:27
77
81
msgid ""
78
82
"A typical use case for :mod:`!threading` includes managing a pool of worker "
79
83
"threads that can process multiple tasks concurrently. Here's a basic "
80
84
"example of creating and starting threads using :class:`~threading.Thread`::"
81
85
msgstr ""
86
+ "典型的 :mod:`!threading` 使用场景包括管理一个工作线程池来并发地处理多个任务。 下面是一个使用 "
87
+ ":class:`~threading.Thread` 创建并启动线程的简单示例::"
82
88
83
89
#: ../../library/threading.rst:31
84
90
msgid ""
@@ -111,6 +117,34 @@ msgid ""
111
117
"for t in threads:\n"
112
118
" t.join()"
113
119
msgstr ""
120
+ "import threading\n"
121
+ "import time\n"
122
+ "\n"
123
+ "def crawl(link, delay=3):\n"
124
+ "print(f\" crawl started for {link}\" )\n"
125
+ "time.sleep(delay) # 阻塞 I/O (模拟网络请求)\n"
126
+ "print(f\" crawl ended for {link}\" )\n"
127
+ "\n"
128
+ "links = [\n"
129
+ "\" https://python.org\" ,\n"
130
+ "\" https://docs.python.org\" ,\n"
131
+ "\" https://peps.python.org\" ,\n"
132
+ "]\n"
133
+ "\n"
134
+ "# 针对每个链接启动线程\n"
135
+ "threads = []\n"
136
+ "for link in links:\n"
137
+ "# 使用 `args` 传入位置参数并使用 `kwargs` 传入关键字参数\n"
138
+ "t = threading.Thread(target=crawl, args=(link,), kwargs={\" delay\" : 2})\n"
139
+ "threads.append(t)\n"
140
+ "\n"
141
+ "# 启动每个线程\n"
142
+ "for t in threads:\n"
143
+ "t.start()\n"
144
+ "\n"
145
+ "# 等待所有线程结束\n"
146
+ "for t in threads:\n"
147
+ "t.join()"
114
148
115
149
#: ../../library/threading.rst:60
116
150
msgid "This module used to be optional, it is now always available."
@@ -165,7 +199,7 @@ msgstr ""
165
199
166
200
#: ../../library/threading.rst:95
167
201
msgid "GIL and performance considerations"
168
- msgstr ""
202
+ msgstr "GIL 和性能的考量 "
169
203
170
204
#: ../../library/threading.rst:97
171
205
msgid ""
@@ -177,13 +211,18 @@ msgid ""
177
211
"bytecode at a time. Despite this, threads remain a useful tool for achieving"
178
212
" concurrency in many scenarios."
179
213
msgstr ""
214
+ "与使用多个进程来绕过 :term:`global interpreter lock` (GIL) 的 :mod:`multiprocessing` "
215
+ "模块不同,threading 模块是在单个进程内部操作的,这意味着所有线程共享相同的内存空间。 不过,对于 CPU 密集型任务来说 GIL 会限制 "
216
+ "threading 带来的性能提升,因为在同一时刻只有一个线程能执行 Python 字节码。 尽管如此,在许多场景中线程仍然是实现并发的有用工具。"
180
217
181
218
#: ../../library/threading.rst:105
182
219
msgid ""
183
220
"As of Python 3.13, experimental :term:`free-threaded <free threading>` "
184
221
"builds can disable the GIL, enabling true parallel execution of threads, but"
185
222
" this feature is not available by default (see :pep:`703`)."
186
223
msgstr ""
224
+ "对于 Python 3.13,实验性的 :term:`自由线程 <free threading>` 构建版可以禁用 "
225
+ "GIL,启用真正的线程并行执行,但此特性在默认情况下不可用 (参见 :pep:`703`)。"
187
226
188
227
#: ../../library/threading.rst:112
189
228
msgid "Reference"
@@ -210,6 +249,8 @@ msgid ""
210
249
"through the :mod:`!threading` module, a dummy thread object with limited "
211
250
"functionality is returned."
212
251
msgstr ""
252
+ "返回当前 :class:`Thread` 对象,与调用方的控制线程。 如果调用方的控制线程不是通过 :mod:`!threading` "
253
+ "模块创建的,则会返回一个功能受限的假线程对象。"
213
254
214
255
#: ../../library/threading.rst:132
215
256
msgid ""
@@ -336,12 +377,14 @@ msgid ""
336
377
"module. The *func* will be passed to :func:`sys.settrace` for each thread, "
337
378
"before its :meth:`~Thread.run` method is called."
338
379
msgstr ""
380
+ "为所有从 :mod:`!threading` 模块启动的线程设置追踪函数,在每个线程的 :meth:`~Thread.run` "
381
+ "方法被调用前,*func* 会被传递给 :func:`sys.settrace`。"
339
382
340
383
#: ../../library/threading.rst:230
341
384
msgid ""
342
385
"Set a trace function for all threads started from the :mod:`!threading` "
343
386
"module and all Python threads that are currently executing."
344
- msgstr ""
387
+ msgstr "为从 :mod:`!threading` 模块启动的所有线程以及当前正在执行的所有 Python 线程设置追踪函数。 "
345
388
346
389
#: ../../library/threading.rst:233
347
390
msgid ""
@@ -360,12 +403,14 @@ msgid ""
360
403
"module. The *func* will be passed to :func:`sys.setprofile` for each "
361
404
"thread, before its :meth:`~Thread.run` method is called."
362
405
msgstr ""
406
+ "为从 :mod:`!threading` 模块启动的所有线程设置性能分析函数。 在每个线程的 :meth:`~Thread.run` "
407
+ "方法被调用前,*func* 会被传递给 :func:`sys.setprofile`。"
363
408
364
409
#: ../../library/threading.rst:259
365
410
msgid ""
366
411
"Set a profile function for all threads started from the :mod:`!threading` "
367
412
"module and all Python threads that are currently executing."
368
- msgstr ""
413
+ msgstr "为从 :mod:`!threading` 模块启动的所有线程和当前正在执行和的所有 Python 线程设置性能分析函数。 "
369
414
370
415
#: ../../library/threading.rst:262
371
416
msgid ""
@@ -448,7 +493,7 @@ msgstr "下述方法的执行都是原子性的。"
448
493
449
494
#: ../../library/threading.rst:325
450
495
msgid "Thread-local data"
451
- msgstr ""
496
+ msgstr "线程局部数据 "
452
497
453
498
#: ../../library/threading.rst:327
454
499
msgid ""
@@ -720,7 +765,7 @@ msgstr "一个代表线程本地数据的类。"
720
765
721
766
#: ../../library/threading.rst:457
722
767
msgid "Thread objects"
723
- msgstr ""
768
+ msgstr "线程对象 "
724
769
725
770
#: ../../library/threading.rst:459
726
771
msgid ""
@@ -927,7 +972,7 @@ msgstr ""
927
972
928
973
#: ../../library/threading.rst:573
929
974
msgid "Set the operating system thread name."
930
- msgstr ""
975
+ msgstr "设置操作系统线程名称。 "
931
976
932
977
#: ../../library/threading.rst:578
933
978
msgid "Method representing the thread's activity."
@@ -1023,7 +1068,7 @@ msgstr ""
1023
1068
1024
1069
#: ../../library/threading.rst:630
1025
1070
msgid "May raise :exc:`PythonFinalizationError`."
1026
- msgstr ""
1071
+ msgstr "可能引发 :exc:`PythonFinalizationError`。 "
1027
1072
1028
1073
#: ../../library/threading.rst:634
1029
1074
msgid ""
@@ -1123,7 +1168,7 @@ msgstr "已被弃用的 :attr:`~Thread.daemon` 的取值/设值 API;请改为
1123
1168
1124
1169
#: ../../library/threading.rst:713
1125
1170
msgid "Lock objects"
1126
- msgstr ""
1171
+ msgstr "Lock 对象 "
1127
1172
1128
1173
#: ../../library/threading.rst:715
1129
1174
msgid ""
@@ -1237,7 +1282,7 @@ msgstr "现在如果底层线程实现支持,则可以通过POSIX上的信号
1237
1282
1238
1283
#: ../../library/threading.rst:780
1239
1284
msgid "Lock acquisition can now be interrupted by signals on Windows."
1240
- msgstr ""
1285
+ msgstr "在 Windows 上现在可以通过信号来中断锁的获取。 "
1241
1286
1242
1287
#: ../../library/threading.rst:786
1243
1288
msgid ""
@@ -1266,7 +1311,7 @@ msgstr "当锁被获取时,返回 ``True``。"
1266
1311
1267
1312
#: ../../library/threading.rst:806
1268
1313
msgid "RLock objects"
1269
- msgstr ""
1314
+ msgstr "RLock 对象 "
1270
1315
1271
1316
#: ../../library/threading.rst:808
1272
1317
msgid ""
@@ -1417,11 +1462,11 @@ msgstr "只有在调用方线程持有锁时才能调用此方法。 如果在
1417
1462
1418
1463
#: ../../library/threading.rst:908 ../../library/threading.rst:1007
1419
1464
msgid "Return a boolean indicating whether this object is locked right now."
1420
- msgstr ""
1465
+ msgstr "返回一个指明该对象目前是否被锁定的布尔值。 "
1421
1466
1422
1467
#: ../../library/threading.rst:916
1423
1468
msgid "Condition objects"
1424
- msgstr ""
1469
+ msgstr "Condition 对象 "
1425
1470
1426
1471
#: ../../library/threading.rst:918
1427
1472
msgid ""
@@ -1725,7 +1770,7 @@ msgstr "``notifyAll`` 方法是此方法的已弃用别名。"
1725
1770
1726
1771
#: ../../library/threading.rst:1094
1727
1772
msgid "Semaphore objects"
1728
- msgstr ""
1773
+ msgstr "Semaphore 对象 "
1729
1774
1730
1775
#: ../../library/threading.rst:1096
1731
1776
msgid ""
@@ -1844,7 +1889,7 @@ msgstr ""
1844
1889
1845
1890
#: ../../library/threading.rst:1175
1846
1891
msgid ":class:`Semaphore` example"
1847
- msgstr ""
1892
+ msgstr ":class:`Semaphore` 示例 "
1848
1893
1849
1894
#: ../../library/threading.rst:1177
1850
1895
msgid ""
@@ -1896,7 +1941,7 @@ msgstr "使用有界信号量能减少这种编程错误:信号量的释放次
1896
1941
1897
1942
#: ../../library/threading.rst:1203
1898
1943
msgid "Event objects"
1899
- msgstr ""
1944
+ msgstr "Event 对象 "
1900
1945
1901
1946
#: ../../library/threading.rst:1205
1902
1947
msgid ""
@@ -1969,7 +2014,7 @@ msgstr "当提供了 timeout 参数且不为 ``None`` 时,它应当为一个
1969
2014
1970
2015
#: ../../library/threading.rst:1260
1971
2016
msgid "Timer objects"
1972
- msgstr ""
2017
+ msgstr "Timer 对象 "
1973
2018
1974
2019
#: ../../library/threading.rst:1262
1975
2020
msgid ""
@@ -2028,7 +2073,7 @@ msgstr "停止定时器并取消执行计时器将要执行的操作。仅当计
2028
2073
2029
2074
#: ../../library/threading.rst:1298
2030
2075
msgid "Barrier objects"
2031
- msgstr ""
2076
+ msgstr "Barrier 对象 "
2032
2077
2033
2078
#: ../../library/threading.rst:1302
2034
2079
msgid ""