-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathsynchronization.po
More file actions
428 lines (370 loc) · 18.2 KB
/
synchronization.po
File metadata and controls
428 lines (370 loc) · 18.2 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# 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.
#
# Translators:
# Rafael Fontenelle <rffontenelle@gmail.com>, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-05-08 19:31+0000\n"
"PO-Revision-Date: 2026-05-08 17:16+0000\n"
"Last-Translator: Rafael Fontenelle <rffontenelle@gmail.com>, 2026\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../c-api/synchronization.rst:6
msgid "Synchronization primitives"
msgstr "同步原语"
#: ../../c-api/synchronization.rst:8
msgid "The C-API provides a basic mutual exclusion lock."
msgstr "C-API 提供了一个基本的互斥锁。"
#: ../../c-api/synchronization.rst:12
msgid ""
"A mutual exclusion lock. The :c:type:`!PyMutex` should be initialized to "
"zero to represent the unlocked state. For example::"
msgstr "一个互斥锁。 :c:type:`!PyMutex` 应当被初始化为零以代表未加锁状态。例如::"
#: ../../c-api/synchronization.rst:15
msgid "PyMutex mutex = {0};"
msgstr "PyMutex mutex = {0};"
#: ../../c-api/synchronization.rst:17
msgid ""
"Instances of :c:type:`!PyMutex` should not be copied or moved. Both the "
"contents and address of a :c:type:`!PyMutex` are meaningful, and it must "
"remain at a fixed, writable location in memory."
msgstr ""
":c:type:`!PyMutex` 的实例不应被拷贝或移动。 :c:type:`!PyMutex` "
"的内容和地址都是有意义的,它必须在内存中保持一个固定的、可写的位置。"
#: ../../c-api/synchronization.rst:23
msgid ""
"A :c:type:`!PyMutex` currently occupies one byte, but the size should be "
"considered unstable. The size may change in future Python releases without "
"a deprecation period."
msgstr ""
":c:type:`!PyMutex` 目前占用一个字节,但这个大小应当被视为是不稳定的。这个大小可能在未来的 Python "
"发布版中发生改变而不会设置弃用期。"
#: ../../c-api/synchronization.rst:31
msgid ""
"Lock mutex *m*. If another thread has already locked it, the calling thread"
" will block until the mutex is unlocked. While blocked, the thread will "
"temporarily detach the :term:`thread state <attached thread state>` if one "
"exists."
msgstr ""
"锁定互斥锁 *m*。如果另一个线程已经锁定了它,调用方线程将会阻塞直到互斥锁被解锁。在阻塞期间,如果线程存在 :term:`线程状态 <attached"
" thread state>` 则会临时释放它。"
#: ../../c-api/synchronization.rst:39
msgid ""
"Unlock mutex *m*. The mutex must be locked --- otherwise, the function will "
"issue a fatal error."
msgstr "解锁互斥锁 *m*。该互斥锁必须已被锁定 --- 否则,此函数将发生致命错误。"
#: ../../c-api/synchronization.rst:46
msgid "Returns non-zero if the mutex *m* is currently locked, zero otherwise."
msgstr "若互斥锁 *m* 当前处于锁定状态,则返回非零值;否则返回零。"
#: ../../c-api/synchronization.rst:50
msgid ""
"This function is intended for use in assertions and debugging only and "
"should not be used to make concurrency control decisions, as the lock state "
"may change immediately after the check."
msgstr "此函数仅适用于断言和调试场景,请勿将其用于并发控制决策,因为锁状态可能在检查后立即发生变化。"
#: ../../c-api/synchronization.rst:59
msgid "Python critical section API"
msgstr "Python 关键节 API"
#: ../../c-api/synchronization.rst:61
msgid ""
"The critical section API provides a deadlock avoidance layer on top of per-"
"object locks for :term:`free-threaded <free threading>` CPython. They are "
"intended to replace reliance on the :term:`global interpreter lock`, and are"
" no-ops in versions of Python with the global interpreter lock."
msgstr ""
"此关键节 API 为 :term:`自由线程 <free threading>` CPython 的每对象锁之上提供了一个死锁避免层。它们旨在替代对 "
":term:`global interpreter lock` 的依赖,而在具有全局解释器锁的 Python 版本上将不做任何操作。"
#: ../../c-api/synchronization.rst:66
msgid ""
"Critical sections are intended to be used for custom types implemented in "
"C-API extensions. They should generally not be used with built-in types like"
" :class:`list` and :class:`dict` because their public C-APIs already use "
"critical sections internally, with the notable exception of "
":c:func:`PyDict_Next`, which requires critical section to be acquired "
"externally."
msgstr ""
"关键节被设计用于在 C-API 扩展中实现的自定义类型。它们通常不应当被用于内置类型如 :class:`list` 和 :class:`dict` "
"因为它们的公有 C-API 已经在内部使用了关键节,一个显著的例外是 :c:func:`PyDict_Next`,它需要在外部获取关键节。"
#: ../../c-api/synchronization.rst:73
msgid ""
"Critical sections avoid deadlocks by implicitly suspending active critical "
"sections, hence, they do not provide exclusive access such as provided by "
"traditional locks like :c:type:`PyMutex`. When a critical section is "
"started, the per-object lock for the object is acquired. If the code "
"executed inside the critical section calls C-API functions then it can "
"suspend the critical section thereby releasing the per-object lock, so other"
" threads can acquire the per-object lock for the same object."
msgstr ""
"关键节是通过隐式地挂起活动关键节来避免死锁的,因此,它们并不提供传统锁如 :c:type:`PyMutex` 所提供的那种独占访问。 "
"当一个关键节启动时,将会获取对象的每对象锁。如果关键节内部执行的代码调用了 C-API "
"函数那么它可以挂起关键节从而释放这个每对象锁,这样其他线程就可以获取同一个对象的每对象锁。"
#: ../../c-api/synchronization.rst:81
msgid ""
"Variants that accept :c:type:`PyMutex` pointers rather than Python objects "
"are also available. Use these variants to start a critical section in a "
"situation where there is no :c:type:`PyObject` -- for example, when working "
"with a C type that does not extend or wrap :c:type:`PyObject` but still "
"needs to call into the C API in a manner that might lead to deadlocks."
msgstr ""
"此外,还提供了接受 :c:type:`PyMutex` 指针(而非 Python 对象)的函数变体。当你处于没有 :c:type:`PyObject` "
"的场景中时(例如,处理一个既未继承也未封装 :c:type:`PyObject` 的 C 类型,但仍需以可能导致死锁的方式调用 C "
"API),请使用这些变体来启动临界区。"
#: ../../c-api/synchronization.rst:87
msgid ""
"The functions and structs used by the macros are exposed for cases where C "
"macros are not available. They should only be used as in the given macro "
"expansions. Note that the sizes and contents of the structures may change in"
" future Python versions."
msgstr ""
"宏所使用的函数和结构体是针对 C 宏不可用的场景而公开的。它们应当仅被用于给定的宏扩展中。请注意这些结构体的大小和内容在未来的 Python "
"版本中可能发生改变。"
#: ../../c-api/synchronization.rst:94
msgid ""
"Operations that need to lock two objects at once must use "
":c:macro:`Py_BEGIN_CRITICAL_SECTION2`. You *cannot* use nested critical "
"sections to lock more than one object at once, because the inner critical "
"section may suspend the outer critical sections. This API does not provide "
"a way to lock more than two objects at once."
msgstr ""
"需要同时锁定两个对象的操作必须使用 :c:macro:`Py_BEGIN_CRITICAL_SECTION2`。你 *不可* "
"使用嵌套的关键节来同时锁定一个以上的对象,因为内层的关键节可能会挂起外层的关键节。这个 API 没有提供同时锁定两个以上对象的办法。"
#: ../../c-api/synchronization.rst:100
msgid "Example usage::"
msgstr "用法示例::"
#: ../../c-api/synchronization.rst:102
msgid ""
"static PyObject *\n"
"set_field(MyObject *self, PyObject *value)\n"
"{\n"
" Py_BEGIN_CRITICAL_SECTION(self);\n"
" Py_SETREF(self->field, Py_XNewRef(value));\n"
" Py_END_CRITICAL_SECTION();\n"
" Py_RETURN_NONE;\n"
"}"
msgstr ""
"static PyObject *\n"
"set_field(MyObject *self, PyObject *value)\n"
"{\n"
" Py_BEGIN_CRITICAL_SECTION(self);\n"
" Py_SETREF(self->field, Py_XNewRef(value));\n"
" Py_END_CRITICAL_SECTION();\n"
" Py_RETURN_NONE;\n"
"}"
#: ../../c-api/synchronization.rst:111
msgid ""
"In the above example, :c:macro:`Py_SETREF` calls :c:macro:`Py_DECREF`, which"
" can call arbitrary code through an object's deallocation function. The "
"critical section API avoids potential deadlocks due to reentrancy and lock "
"ordering by allowing the runtime to temporarily suspend the critical section"
" if the code triggered by the finalizer blocks and calls "
":c:func:`PyEval_SaveThread`."
msgstr ""
"在上面的例子中,:c:macro:`Py_SETREF` 调用了 "
":c:macro:`Py_DECREF`,它可以通过一个对象的取消分配函数来调用任意代码。当由最终化器触发的代码发生阻塞并调用 "
":c:func:`PyEval_SaveThread` 时关键节 API 将通过允许运行临时挂起关键节来避免由于重入和锁顺序导致的潜在死锁。"
#: ../../c-api/synchronization.rst:119
msgid ""
"Acquires the per-object lock for the object *op* and begins a critical "
"section."
msgstr "为对象 *op* 获取每对象锁并开始一个关键节。"
#: ../../c-api/synchronization.rst:122 ../../c-api/synchronization.rst:136
#: ../../c-api/synchronization.rst:153 ../../c-api/synchronization.rst:168
#: ../../c-api/synchronization.rst:182 ../../c-api/synchronization.rst:199
msgid "In the free-threaded build, this macro expands to::"
msgstr "在自由线程构建版中,该宏将扩展为::"
#: ../../c-api/synchronization.rst:124
msgid ""
"{\n"
" PyCriticalSection _py_cs;\n"
" PyCriticalSection_Begin(&_py_cs, (PyObject*)(op))"
msgstr ""
"{\n"
" PyCriticalSection _py_cs;\n"
" PyCriticalSection_Begin(&_py_cs, (PyObject*)(op))"
#: ../../c-api/synchronization.rst:128 ../../c-api/synchronization.rst:174
msgid "In the default build, this macro expands to ``{``."
msgstr "在默认构建版中,该宏将扩展为 ``{``。"
#: ../../c-api/synchronization.rst:134
msgid "Locks the mutex *m* and begins a critical section."
msgstr "锁定互斥锁 *m* 并开始一个临界区。"
#: ../../c-api/synchronization.rst:138
msgid ""
"{\n"
" PyCriticalSection _py_cs;\n"
" PyCriticalSection_BeginMutex(&_py_cs, m)"
msgstr ""
"{\n"
" PyCriticalSection _py_cs;\n"
" PyCriticalSection_BeginMutex(&_py_cs, m)"
#: ../../c-api/synchronization.rst:142
msgid ""
"Note that unlike :c:macro:`Py_BEGIN_CRITICAL_SECTION`, there is no cast for "
"the argument of the macro - it must be a :c:type:`PyMutex` pointer."
msgstr ""
"需要注意的是,与 :c:macro:`Py_BEGIN_CRITICAL_SECTION` 不同,此宏的参数无需类型转换——它必须是一个 "
":c:type:`PyMutex` 指针。"
#: ../../c-api/synchronization.rst:145 ../../c-api/synchronization.rst:191
msgid "On the default build, this macro expands to ``{``."
msgstr "在默认构建版中,该宏将扩展为 ``{``。"
#: ../../c-api/synchronization.rst:151
msgid "Ends the critical section and releases the per-object lock."
msgstr "结束关键节并释放每对象锁。"
#: ../../c-api/synchronization.rst:155
msgid ""
" PyCriticalSection_End(&_py_cs);\n"
"}"
msgstr ""
" PyCriticalSection_End(&_py_cs);\n"
"}"
#: ../../c-api/synchronization.rst:158 ../../c-api/synchronization.rst:204
msgid "In the default build, this macro expands to ``}``."
msgstr "在默认构建版中,该宏将扩展为 ``}``。"
#: ../../c-api/synchronization.rst:164
msgid ""
"Acquires the per-object locks for the objects *a* and *b* and begins a "
"critical section. The locks are acquired in a consistent order (lowest "
"address first) to avoid lock ordering deadlocks."
msgstr "为对象 *a* 和 *b* 获取每对象锁并开始一个关键节。 这些锁将按一致的顺序获取(最低的地址在最前)以避免锁排序死锁。"
#: ../../c-api/synchronization.rst:170
msgid ""
"{\n"
" PyCriticalSection2 _py_cs2;\n"
" PyCriticalSection2_Begin(&_py_cs2, (PyObject*)(a), (PyObject*)(b))"
msgstr ""
"{\n"
" PyCriticalSection2 _py_cs2;\n"
" PyCriticalSection2_Begin(&_py_cs2, (PyObject*)(a), (PyObject*)(b))"
#: ../../c-api/synchronization.rst:180
msgid "Locks the mutexes *m1* and *m2* and begins a critical section."
msgstr "锁定互斥锁 *m1* 和 *m2* 并开始一个临界区。"
#: ../../c-api/synchronization.rst:184
msgid ""
"{\n"
" PyCriticalSection2 _py_cs2;\n"
" PyCriticalSection2_BeginMutex(&_py_cs2, m1, m2)"
msgstr ""
"{\n"
" PyCriticalSection2 _py_cs2;\n"
" PyCriticalSection2_BeginMutex(&_py_cs2, m1, m2)"
#: ../../c-api/synchronization.rst:188
msgid ""
"Note that unlike :c:macro:`Py_BEGIN_CRITICAL_SECTION2`, there is no cast for"
" the arguments of the macro - they must be :c:type:`PyMutex` pointers."
msgstr ""
"需要注意的是,与 :c:macro:`Py_BEGIN_CRITICAL_SECTION2` 不同,此宏的参数无需类型转换——它们必须是 "
":c:type:`PyMutex` 指针。"
#: ../../c-api/synchronization.rst:197
msgid "Ends the critical section and releases the per-object locks."
msgstr "结束关键节并释放每对象锁。"
#: ../../c-api/synchronization.rst:201
msgid ""
" PyCriticalSection2_End(&_py_cs2);\n"
"}"
msgstr ""
" PyCriticalSection2_End(&_py_cs2);\n"
"}"
#: ../../c-api/synchronization.rst:210
msgid "Legacy locking APIs"
msgstr "旧式加锁 API"
#: ../../c-api/synchronization.rst:212
msgid ""
"These APIs are obsolete since Python 3.13 with the introduction of "
":c:type:`PyMutex`."
msgstr "这些 API 自 Python 3.13 起已随 :c:type:`PyMutex` 的引入而过时。"
#: ../../c-api/synchronization.rst:218
msgid "A pointer to a mutual exclusion lock."
msgstr "一个指向互斥锁的指针。"
#: ../../c-api/synchronization.rst:223
msgid "The result of acquiring a lock with a timeout."
msgstr "附带超时获取锁操作的结果。"
#: ../../c-api/synchronization.rst:229
msgid "Failed to acquire the lock."
msgstr "获取锁失败。"
#: ../../c-api/synchronization.rst:233
msgid "The lock was successfully acquired."
msgstr "锁已被成功获取。"
#: ../../c-api/synchronization.rst:237
msgid "The lock was interrupted by a signal."
msgstr "锁被一个信号中断。"
#: ../../c-api/synchronization.rst:242
msgid "Allocate a new lock."
msgstr "分配一个新锁。"
#: ../../c-api/synchronization.rst:244
msgid ""
"On success, this function returns a lock; on failure, this function returns "
"``0`` without an exception set."
msgstr "成功时,此函数将返回一个锁;失败时,此函数将返回 ``0`` 且不设置异常。"
#: ../../c-api/synchronization.rst:247 ../../c-api/synchronization.rst:255
#: ../../c-api/synchronization.rst:275 ../../c-api/synchronization.rst:293
#: ../../c-api/synchronization.rst:301
msgid "The caller does not need to hold an :term:`attached thread state`."
msgstr "调用方不需要持有 :term:`attached thread state`。"
#: ../../c-api/synchronization.rst:252
msgid ""
"Destroy *lock*. The lock should not be held by any thread when calling this."
msgstr "销毁 *lock*。在调用此函数时该锁不应被任何线程持有。"
#: ../../c-api/synchronization.rst:260
msgid "Acquire *lock* with a timeout."
msgstr "获取 *lock* 并附带超时控制。"
#: ../../c-api/synchronization.rst:262
msgid ""
"This will wait for *microseconds* microseconds to acquire the lock. If the "
"timeout expires, this function returns :c:enumerator:`PY_LOCK_FAILURE`. If "
"*microseconds* is ``-1``, this will wait indefinitely until the lock has "
"been released."
msgstr ""
"此函数将等待 *microseconds* 微秒以获取锁。如果达到超时限制,此函数将返回 "
":c:enumerator:`PY_LOCK_FAILURE`。如果 *microseconds* 为 ``-1``,它将无限等待直到锁被释放。"
#: ../../c-api/synchronization.rst:267
msgid ""
"If *intr_flag* is ``1``, acquiring the lock may be interrupted by a signal, "
"in which case this function returns :c:enumerator:`PY_LOCK_INTR`. Upon "
"interruption, it's generally expected that the caller makes a call to "
":c:func:`Py_MakePendingCalls` to propagate an exception to Python code."
msgstr ""
"如果 *intr_flag* 为 ``1``,获取锁可能会被信号中断,在这种情况下此函数将返回 "
":c:enumerator:`PY_LOCK_INTR`。当被中断时,通常会预期调用方将执行对 "
":c:func:`Py_MakePendingCalls` 的调用以将一个异常传播给 Python 代码。"
#: ../../c-api/synchronization.rst:272
msgid ""
"If the lock is successfully acquired, this function returns "
":c:enumerator:`PY_LOCK_ACQUIRED`."
msgstr "如果锁被成功获取,此函数将返回 :c:enumerator:`PY_LOCK_ACQUIRED`。"
#: ../../c-api/synchronization.rst:280
msgid "Acquire *lock*."
msgstr "获取 *lock*。"
#: ../../c-api/synchronization.rst:282
msgid ""
"If *waitflag* is ``1`` and another thread currently holds the lock, this "
"function will wait until the lock can be acquired and will always return "
"``1``."
msgstr "如果 *waitflag* 为 ``1`` 且另一个线程目前持有锁,此函数将等待直到锁可被获取并将始终返回 ``1``。"
#: ../../c-api/synchronization.rst:286
msgid ""
"If *waitflag* is ``0`` and another thread holds the lock, this function will"
" not wait and instead return ``0``. If the lock is not held by any other "
"thread, then this function will acquire it and return ``1``."
msgstr ""
"如果 *waitflag* 为 ``0`` 且另一个线程持有锁,此函数将不会等待而是返回 ``0``。如果锁未被另一个线程持有,则此函数将获取它并返回 "
"``1``。"
#: ../../c-api/synchronization.rst:290
msgid ""
"Unlike :c:func:`PyThread_acquire_lock_timed`, acquiring the lock cannot be "
"interrupted by a signal."
msgstr "不同于 :c:func:`PyThread_acquire_lock_timed`,获取锁不会被信号中断。"
#: ../../c-api/synchronization.rst:298
msgid ""
"Release *lock*. If *lock* is not held, then this function issues a fatal "
"error."
msgstr "释放 *lock*。如果 *lock* 未被持有,则此函数将引发致命错误。"