-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathsubinterpreters.po
More file actions
682 lines (595 loc) · 33.2 KB
/
subinterpreters.po
File metadata and controls
682 lines (595 loc) · 33.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# 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/subinterpreters.rst:6
msgid "Multiple interpreters in a Python process"
msgstr ""
#: ../../c-api/subinterpreters.rst:8
msgid ""
"While in most uses, you will only embed a single Python interpreter, there "
"are cases where you need to create several independent interpreters in the "
"same process and perhaps even in the same thread. Sub-interpreters allow you"
" to do that."
msgstr ""
"虽然在大多数用例中,你都只会嵌入一个单独的 Python 解释器,但某些场景需要你在同一个进程甚至同一个线程中创建多个独立的解释器。 "
"子解释器让你能够做到这一点。"
#: ../../c-api/subinterpreters.rst:13
msgid ""
"The \"main\" interpreter is the first one created when the runtime "
"initializes. It is usually the only Python interpreter in a process. Unlike"
" sub-interpreters, the main interpreter has unique process-global "
"responsibilities like signal handling. It is also responsible for execution"
" during runtime initialization and is usually the active interpreter during "
"runtime finalization. The :c:func:`PyInterpreterState_Main` function "
"returns a pointer to its state."
msgstr ""
"“主”解释器是在运行时初始化时创建的第一个解释器。它通常是一个进程中唯一的 Python "
"解释器。与子解释器不同,主解释器具有唯一的进程全局责任比如信号处理等。它还负责在运行时初始化期间的执行并且通常还是运行时最终化期间的活动解释器。:c:func:`PyInterpreterState_Main`"
" 函数将返回一个指向其状态的指针。"
#: ../../c-api/subinterpreters.rst:20
msgid ""
"You can switch between sub-interpreters using the "
":c:func:`PyThreadState_Swap` function. You can create and destroy them using"
" the following functions:"
msgstr "你可以使用 :c:func:`PyThreadState_Swap` 函数在子解释器之间进行切换。你可以使用下列函数来创建和销毁它们:"
#: ../../c-api/subinterpreters.rst:26
msgid ""
"Structure containing most parameters to configure a sub-interpreter. Its "
"values are used only in :c:func:`Py_NewInterpreterFromConfig` and never "
"modified by the runtime."
msgstr ""
"包含用于配置子解释器的大部分形参的结构体。其值仅在 :c:func:`Py_NewInterpreterFromConfig` "
"中被使用而绝不会被运行时所修改。"
#: ../../c-api/subinterpreters.rst:32
msgid "Structure fields:"
msgstr "结构体字段:"
#: ../../c-api/subinterpreters.rst:36
msgid ""
"If this is ``0`` then the sub-interpreter will use its own \"object\" "
"allocator state. Otherwise it will use (share) the main interpreter's."
msgstr "如果该值为 ``0`` 则子解释器将使用自己的“对象”分配器状态。否则它将使用(共享)主解释器的状态。"
#: ../../c-api/subinterpreters.rst:40
msgid ""
"If this is ``0`` then "
":c:member:`~PyInterpreterConfig.check_multi_interp_extensions` must be ``1``"
" (non-zero). If this is ``1`` then :c:member:`~PyInterpreterConfig.gil` must"
" not be :c:macro:`PyInterpreterConfig_OWN_GIL`."
msgstr ""
"如果该值为 ``0`` 则 :c:member:`~PyInterpreterConfig.check_multi_interp_extensions`"
" 必须为 ``1`` (非零值)。如果该值为 ``1`` 则 :c:member:`~PyInterpreterConfig.gil` 不可为 "
":c:macro:`PyInterpreterConfig_OWN_GIL` 选项。"
#: ../../c-api/subinterpreters.rst:48
msgid ""
"If this is ``0`` then the runtime will not support forking the process in "
"any thread where the sub-interpreter is currently active. Otherwise fork is "
"unrestricted."
msgstr "如果该值为 ``0`` 则运行时将不支持在当前激活了子解释器的任何线程中 fork 进程。否则 fork 将不受限制。"
#: ../../c-api/subinterpreters.rst:52
msgid ""
"Note that the :mod:`subprocess` module still works when fork is disallowed."
msgstr "请注意当 fork 被禁止时 :mod:`subprocess` 模块将仍然可用。"
#: ../../c-api/subinterpreters.rst:57
msgid ""
"If this is ``0`` then the runtime will not support replacing the current "
"process via exec (e.g. :func:`os.execv`) in any thread where the sub-"
"interpreter is currently active. Otherwise exec is unrestricted."
msgstr ""
"如果该值为 ``0`` 则运行时将不支持在当前激活了子解释器的任何线程中通过 exec (例如 :func:`os.execv`) 替换当前进程。否则 "
"exec 将不受限制。"
#: ../../c-api/subinterpreters.rst:62
msgid ""
"Note that the :mod:`subprocess` module still works when exec is disallowed."
msgstr "请注意当 exec 被禁止时 :mod:`subprocess` 模块将仍然可用。"
#: ../../c-api/subinterpreters.rst:67
msgid ""
"If this is ``0`` then the sub-interpreter's :mod:`threading` module won't "
"create threads. Otherwise threads are allowed."
msgstr "如果该值为 ``0`` 则子解释器的 :mod:`threading` 模块将不会创建线程。否则线程将被允许。"
#: ../../c-api/subinterpreters.rst:73
msgid ""
"If this is ``0`` then the sub-interpreter's :mod:`threading` module won't "
"create daemon threads. Otherwise daemon threads are allowed (as long as "
":c:member:`~PyInterpreterConfig.allow_threads` is non-zero)."
msgstr ""
"如果该值为 ``0`` 则子解释器的 :mod:`threading` 模块将不会创建守护线程。否则将允许守护线程(只要 "
":c:member:`~PyInterpreterConfig.allow_threads` 是非零值)。"
#: ../../c-api/subinterpreters.rst:80
msgid ""
"If this is ``0`` then all extension modules may be imported, including "
"legacy (single-phase init) modules, in any thread where the sub-interpreter "
"is currently active. Otherwise only multi-phase init extension modules (see "
":pep:`489`) may be imported. (Also see "
":c:macro:`Py_mod_multiple_interpreters`.)"
msgstr ""
"如果该值为 ``0`` 则所有扩展模块均可在当前子解释器被激活的任何线程中被导入,包括旧式的 (单阶段初始化) 模块。否则将只有多阶段初始化扩展模块 "
"(参见 :pep:`489`) 可以被导入。 (另请参阅 :c:macro:`Py_mod_multiple_interpreters`。)"
#: ../../c-api/subinterpreters.rst:87
msgid ""
"This must be ``1`` (non-zero) if "
":c:member:`~PyInterpreterConfig.use_main_obmalloc` is ``0``."
msgstr ""
"如果 :c:member:`~PyInterpreterConfig.use_main_obmalloc` 为 ``0`` 则该值必须为 ``1`` "
"(非零值)。"
#: ../../c-api/subinterpreters.rst:92
msgid ""
"This determines the operation of the GIL for the sub-interpreter. It may be "
"one of the following:"
msgstr "这将确定针对子解释器的 GIL 操作方式。它可以是以下的几种之一:"
#: ../../c-api/subinterpreters.rst:99
msgid "Use the default selection (:c:macro:`PyInterpreterConfig_SHARED_GIL`)."
msgstr "使用默认选择 (:c:macro:`PyInterpreterConfig_SHARED_GIL`)。"
#: ../../c-api/subinterpreters.rst:103
msgid "Use (share) the main interpreter's GIL."
msgstr "使用(共享)主解释器的 GIL。"
#: ../../c-api/subinterpreters.rst:107
msgid "Use the sub-interpreter's own GIL."
msgstr "使用子解释器自己的 GIL。"
#: ../../c-api/subinterpreters.rst:109
msgid ""
"If this is :c:macro:`PyInterpreterConfig_OWN_GIL` then "
":c:member:`PyInterpreterConfig.use_main_obmalloc` must be ``0``."
msgstr ""
"如果该值为 :c:macro:`PyInterpreterConfig_OWN_GIL` 则 "
":c:member:`PyInterpreterConfig.use_main_obmalloc` 必须为 ``0``。"
#: ../../c-api/subinterpreters.rst:123
msgid ""
"Create a new sub-interpreter. This is an (almost) totally separate "
"environment for the execution of Python code. In particular, the new "
"interpreter has separate, independent versions of all imported modules, "
"including the fundamental modules :mod:`builtins`, :mod:`__main__` and "
":mod:`sys`. The table of loaded modules (``sys.modules``) and the module "
"search path (``sys.path``) are also separate. The new environment has no "
"``sys.argv`` variable. It has new standard I/O stream file objects "
"``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` (however these refer to the"
" same underlying file descriptors)."
msgstr ""
"新建一个子解释器。这是一个 (几乎) 完全隔离的 Python 代码执行环境。 "
"特别需要注意,新的子解释器具有全部已导入模块的隔离的、独立的版本,包括基本模块 :mod:`builtins`, :mod:`__main__` 和 "
":mod:`sys` 等。已加载模块表 (``sys.modules``) 和模块搜索路径 (``sys.path``) 也是隔离的。新环境没有 "
"``sys.argv`` 变量。它具有新的标准 I/O 流文件对象 ``sys.stdin``, ``sys.stdout`` 和 "
"``sys.stderr`` (不过这些对象都指向相同的底层文件描述符)。"
#: ../../c-api/subinterpreters.rst:133
msgid ""
"The given *config* controls the options with which the interpreter is "
"initialized."
msgstr "给定的 *config* 控制着初始化解释器所使用的选项。"
#: ../../c-api/subinterpreters.rst:136
msgid ""
"Upon success, *tstate_p* will be set to the first :term:`thread state` "
"created in the new sub-interpreter. This thread state is :term:`attached "
"<attached thread state>`. Note that no actual thread is created; see the "
"discussion of thread states below. If creation of the new interpreter is "
"unsuccessful, *tstate_p* is set to ``NULL``; no exception is set since the "
"exception state is stored in the :term:`attached thread state`, which might "
"not exist."
msgstr ""
"成功后,*tstate_p* 将被设为新的子解释器中创建的第一个 :term:`thread state`。该线程状态是 :term:`已附加的 "
"<attached thread state>`。请注意并没有真实的线程被创建;请参阅下文有关线程状态的讨论。如果新解释器的创建没有成功,则 "
"*tstate_p* 将被设为 ``NULL``;不会设置任何异常因为异常状态是存储在 :term:`attached thread state` "
"中的,而它并不一定存在。"
#: ../../c-api/subinterpreters.rst:145
msgid ""
"Like all other Python/C API functions, an :term:`attached thread state` must"
" be present before calling this function, but it might be detached upon "
"returning. On success, the returned thread state will be :term:`attached "
"<attached thread state>`. If the sub-interpreter is created with its own "
":term:`GIL` then the :term:`attached thread state` of the calling "
"interpreter will be detached. When the function returns, the new "
"interpreter's :term:`thread state` will be :term:`attached <attached thread "
"state>` to the current thread and the previous interpreter's :term:`attached"
" thread state` will remain detached."
msgstr ""
"与所有其他 Python/C API 函数一样,调用此函数前必须存在 :term:`attached thread "
"state`,但返回时该状态可能会被分离。成功时,返回的线程状态将处于 :term:`已附加 <attached thread state>` 状态。 "
"如果子解释器使用自己的 :term:`GIL` 创建,则调用解释器的 :term:`attached thread state` 将被分离。 "
"当函数返回时,新解释器的 :term:`thread state` 将 :term:`已附加 <attached thread state>` "
"到当前线程,而先前解释器的 :term:`attached thread state` 将保持分离状态。"
#: ../../c-api/subinterpreters.rst:156
msgid ""
"Sub-interpreters are most effective when isolated from each other, with "
"certain functionality restricted::"
msgstr "子解释器在彼此相互隔离,并让特定功能受限的情况下是最有效率的::"
#: ../../c-api/subinterpreters.rst:159
msgid ""
"PyInterpreterConfig config = {\n"
" .use_main_obmalloc = 0,\n"
" .allow_fork = 0,\n"
" .allow_exec = 0,\n"
" .allow_threads = 1,\n"
" .allow_daemon_threads = 0,\n"
" .check_multi_interp_extensions = 1,\n"
" .gil = PyInterpreterConfig_OWN_GIL,\n"
"};\n"
"PyThreadState *tstate = NULL;\n"
"PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);\n"
"if (PyStatus_Exception(status)) {\n"
" Py_ExitStatusException(status);\n"
"}"
msgstr ""
"PyInterpreterConfig config = {\n"
" .use_main_obmalloc = 0,\n"
" .allow_fork = 0,\n"
" .allow_exec = 0,\n"
" .allow_threads = 1,\n"
" .allow_daemon_threads = 0,\n"
" .check_multi_interp_extensions = 1,\n"
" .gil = PyInterpreterConfig_OWN_GIL,\n"
"};\n"
"PyThreadState *tstate = NULL;\n"
"PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);\n"
"if (PyStatus_Exception(status)) {\n"
" Py_ExitStatusException(status);\n"
"}"
#: ../../c-api/subinterpreters.rst:174
msgid ""
"Note that the config is used only briefly and does not get modified. During "
"initialization the config's values are converted into various "
":c:type:`PyInterpreterState` values. A read-only copy of the config may be "
"stored internally on the :c:type:`PyInterpreterState`."
msgstr ""
"请注意该配置只会被短暂使用而不会被修改。在初始化期间配置的值会被转换成各种 :c:type:`PyInterpreterState` 值。 "
"配置的只读副本可以被内部存储于 :c:type:`PyInterpreterState` 中。"
#: ../../c-api/subinterpreters.rst:183
msgid "Extension modules are shared between (sub-)interpreters as follows:"
msgstr "扩展模块将以如下方式在(子)解释器之间共享:"
#: ../../c-api/subinterpreters.rst:185
msgid ""
"For modules using multi-phase initialization, e.g. "
":c:func:`PyModule_FromDefAndSpec`, a separate module object is created and "
"initialized for each interpreter. Only C-level static and global variables "
"are shared between these module objects."
msgstr ""
"对于使用多阶段初始化的模块,例如 :c:func:`PyModule_FromDefAndSpec`,将为每个解释器创建并初始化一个单独的模块对象。 "
"只有 C 层级的静态和全局变量能在这些模块 对象之间共享。"
#: ../../c-api/subinterpreters.rst:191
msgid ""
"For modules using legacy :ref:`single-phase initialization <single-phase-"
"initialization>`, e.g. :c:func:`PyModule_Create`, the first time a "
"particular extension is imported, it is initialized normally, and a "
"(shallow) copy of its module's dictionary is squirreled away. When the same "
"extension is imported by another (sub-)interpreter, a new module is "
"initialized and filled with the contents of this copy; the extension's "
"``init`` function is not called. Objects in the module's dictionary thus end"
" up shared across (sub-)interpreters, which might cause unwanted behavior "
"(see `Bugs and caveats`_ below)."
msgstr ""
#: ../../c-api/subinterpreters.rst:203
msgid ""
"Note that this is different from what happens when an extension is imported "
"after the interpreter has been completely re-initialized by calling "
":c:func:`Py_FinalizeEx` and :c:func:`Py_Initialize`; in that case, the "
"extension's ``initmodule`` function *is* called again. As with multi-phase "
"initialization, this means that only C-level static and global variables are"
" shared between these modules."
msgstr ""
"请注意这不同于在调用 :c:func:`Py_FinalizeEx` 和 :c:func:`Py_Initialize` "
"完全重新初始化解释器之后导入扩展时所发生的情况;对于那种情况,扩展的 ``initmodule`` 函数 *会被* 再次调用。 "
"与多阶段初始化一样,这意味着只有 C 层级的静态和全局变量能在这些模块之间共享。"
#: ../../c-api/subinterpreters.rst:223
msgid ""
"Create a new sub-interpreter. This is essentially just a wrapper around "
":c:func:`Py_NewInterpreterFromConfig` with a config that preserves the "
"existing behavior. The result is an unisolated sub-interpreter that shares "
"the main interpreter's GIL, allows fork/exec, allows daemon threads, and "
"allows single-phase init modules."
msgstr ""
"新建一个子解释器。这在本质上只是针对 :c:func:`Py_NewInterpreterFromConfig` 的包装器,其配置保留了现有的行为。 "
"结果是一个未隔离的子解释器,它会共享主解释器的 GIL,允许 fork/exec,允许守护线程,也允许单阶段初始化模块。"
#: ../../c-api/subinterpreters.rst:235
msgid ""
"Destroy the (sub-)interpreter represented by the given :term:`thread state`."
" The given thread state must be :term:`attached <attached thread state>`. "
"When the call returns, there will be no :term:`attached thread state`. All "
"thread states associated with this interpreter are destroyed."
msgstr ""
"销毁由给定 :term:`thread state` 表示的(子)解释器。给定的线程状态必须处于 :term:`已附加 <attached thread"
" state>` 状态。调用返回时,将不存在任何 :term:`attached thread state`。与此解释器关联的所有线程状态都会被销毁。"
#: ../../c-api/subinterpreters.rst:240
msgid ""
":c:func:`Py_FinalizeEx` will destroy all sub-interpreters that haven't been "
"explicitly destroyed at that point."
msgstr ":c:func:`Py_FinalizeEx` 将销毁所有在当前时间点上尚未被明确销毁的子解释器。"
#: ../../c-api/subinterpreters.rst:247
msgid "A per-interpreter GIL"
msgstr ""
#: ../../c-api/subinterpreters.rst:251
msgid ""
"Using :c:func:`Py_NewInterpreterFromConfig` you can create a sub-interpreter"
" that is completely isolated from other interpreters, including having its "
"own GIL. The most important benefit of this isolation is that such an "
"interpreter can execute Python code without being blocked by other "
"interpreters or blocking any others. Thus a single Python process can truly"
" take advantage of multiple CPU cores when running Python code. The "
"isolation also encourages a different approach to concurrency than that of "
"just using threads. (See :pep:`554` and :pep:`684`.)"
msgstr ""
"使用 :c:func:`Py_NewInterpreterFromConfig` 你将可以创建一个与其他解释器完全隔离的子解释器,包括具有自己的 "
"GIL。这种隔离带来的最大好处在于这样的解释器执行 Python 代码时不会被其他解释器所阻塞或者阻塞任何其他解释器。因此在运行 Python "
"代码时单个 Python 进程可以真正地利用多个 CPU 核心。这种隔离还能鼓励开发者采取不同于仅使用线程的并发方式。 (参见 :pep:`554` 和"
" :pep:`684` )。"
#: ../../c-api/subinterpreters.rst:261
msgid ""
"Using an isolated interpreter requires vigilance in preserving that "
"isolation. That especially means not sharing any objects or mutable state "
"without guarantees about thread-safety. Even objects that are otherwise "
"immutable (e.g. ``None``, ``(1, 5)``) can't normally be shared because of "
"the refcount. One simple but less-efficient approach around this is to use "
"a global lock around all use of some state (or object). Alternately, "
"effectively immutable objects (like integers or strings) can be made safe in"
" spite of their refcounts by making them :term:`immortal`. In fact, this has"
" been done for the builtin singletons, small integers, and a number of other"
" builtin objects."
msgstr ""
"使用隔离的解释器要求谨慎地保持隔离状态。尤其是意味着不要在未确保线程安全的情况下共享任何对象或可变的状态。由于引用计数的存在即使是在其他情况下不可变的对象"
" (例如 ``None``, ``(1, 5)``) 通常也不可被共享。 针对此问题的一种简单但效率较低的解决方式是在使用某些状态 (或对象) "
"时总是使用一个全局锁。或者,实际上不可变的对象 (如整数或字符串) 可以通过将其设为 :term:`immortal` "
"对象而无视其引用计数来确保其安全性。事实上,对于内置单例、小整数和其他一些内置对象都是这样做的。"
#: ../../c-api/subinterpreters.rst:272
msgid ""
"If you preserve isolation then you will have access to proper multi-core "
"computing without the complications that come with free-threading. Failure "
"to preserve isolation will expose you to the full consequences of free-"
"threading, including races and hard-to-debug crashes."
msgstr ""
"如果你能保持隔离状态那么你将能获得真正的多核计算能力而不会遇到自由线程所带来的复杂性。 "
"如果未能保持隔离状态那么你将面对自由线程所带来的全部后果,包括线程竞争和难以调试的崩溃。"
#: ../../c-api/subinterpreters.rst:277
msgid ""
"Aside from that, one of the main challenges of using multiple isolated "
"interpreters is how to communicate between them safely (not break isolation)"
" and efficiently. The runtime and stdlib do not provide any standard "
"approach to this yet. A future stdlib module would help mitigate the effort"
" of preserving isolation and expose effective tools for communicating (and "
"sharing) data between interpreters."
msgstr ""
"除此之外,使用多个相互隔离的解释器的一个主要挑战是如何在它们之间安全 (不破坏隔离状态)、高效地进行通信。运行时和标准库还没有为此提供任何标准方式。 "
"未来的标准库模块将会帮助减少保持隔离状态所需的工作量并为解释器之间的数据通信(和共享)公开有效的工具。"
#: ../../c-api/subinterpreters.rst:286
msgid "Bugs and caveats"
msgstr "错误和注意事项"
#: ../../c-api/subinterpreters.rst:288
msgid ""
"Because sub-interpreters (and the main interpreter) are part of the same "
"process, the insulation between them isn't perfect --- for example, using "
"low-level file operations like :func:`os.close` they can (accidentally or "
"maliciously) affect each other's open files. Because of the way extensions "
"are shared between (sub-)interpreters, some extensions may not work "
"properly; this is especially likely when using single-phase initialization "
"or (static) global variables. It is possible to insert objects created in "
"one sub-interpreter into a namespace of another (sub-)interpreter; this "
"should be avoided if possible."
msgstr ""
#: ../../c-api/subinterpreters.rst:298
msgid ""
"Special care should be taken to avoid sharing user-defined functions, "
"methods, instances or classes between sub-interpreters, since import "
"operations executed by such objects may affect the wrong (sub-)interpreter's"
" dictionary of loaded modules. It is equally important to avoid sharing "
"objects from which the above are reachable."
msgstr ""
"应当特别注意避免在子解释器之间共享用户自定义的函数、方法、实例或类,因为由这些对象执行的导入 操作可能会影响错误的已加载模块的 (子) 解释器的字典。 "
"同样重要的一点是应当避免共享可被上述对象访问的对象。"
#: ../../c-api/subinterpreters.rst:304
msgid ""
"Also note that combining this functionality with ``PyGILState_*`` APIs is "
"delicate, because these APIs assume a bijection between Python thread states"
" and OS-level threads, an assumption broken by the presence of sub-"
"interpreters. It is highly recommended that you don't switch sub-"
"interpreters between a pair of matching :c:func:`PyGILState_Ensure` and "
":c:func:`PyGILState_Release` calls. Furthermore, extensions (such as "
":mod:`ctypes`) using these APIs to allow calling of Python code from non-"
"Python created threads will probably be broken when using sub-interpreters."
msgstr ""
"还要注意的一点是将此功能与 ``PyGILState_*`` API 结合使用是很微妙的,因为这些 API 会假定 Python "
"线程状态与操作系统级线程之间存在双向投影关系,而子解释器的存在打破了这一假定。强烈建议你不要在一对互相匹配的 "
":c:func:`PyGILState_Ensure` 和 :c:func:`PyGILState_Release` 调用之间切换子解释器。 "
"此外,使用这些 API 以允许从非 Python 创建的线程调用 Python 代码的扩展 (如 :mod:`ctypes`) "
"在使用子解释器时很可能会出现问题。"
#: ../../c-api/subinterpreters.rst:315
msgid "High-level APIs"
msgstr "高层级 API"
#: ../../c-api/subinterpreters.rst:319
msgid ""
"This data structure represents the state shared by a number of cooperating "
"threads. Threads belonging to the same interpreter share their module "
"administration and a few other internal items. There are no public members "
"in this structure."
msgstr "该数据结构代表多个合作线程所共享的状态。属于同一解释器的线程将共享其模块管理以及其他一些内部条目。该结构体中不包含公有成员。"
#: ../../c-api/subinterpreters.rst:324
msgid ""
"Threads belonging to different interpreters initially share nothing, except "
"process state like available memory, open file descriptors and such. The "
"global interpreter lock is also shared by all threads, regardless of to "
"which interpreter they belong."
msgstr ""
"最初归属于不同解释器的线程不会共享任何东西,但进程状态如可用内存、打开的文件描述符等等除外。全局解释器锁也会被所有线程共享,无论它们归属于哪个解释器。"
#: ../../c-api/subinterpreters.rst:331
msgid ""
":pep:`684` introduced the possibility of a :ref:`per-interpreter GIL <per-"
"interpreter-gil>`. See :c:func:`Py_NewInterpreterFromConfig`."
msgstr ""
":pep:`684` 引入了 :ref:`单解释器 GIL <per-interpreter-gil>` 的可能性。请参阅 "
":c:func:`Py_NewInterpreterFromConfig` 函数。"
#: ../../c-api/subinterpreters.rst:338
msgid "Get the current interpreter."
msgstr "获取当前解释器。"
#: ../../c-api/subinterpreters.rst:340
msgid ""
"Issue a fatal error if there is no :term:`attached thread state`. It cannot "
"return NULL."
msgstr "如果没有 :term:`attached thread state` 则会发生致命错误。 此函数不会返回 NULL。"
#: ../../c-api/subinterpreters.rst:348
msgid ""
"Return the interpreter's unique ID. If there was any error in doing so then"
" ``-1`` is returned and an error is set."
msgstr "返回解释器的唯一 ID。如果执行过程中发生任何错误则将返回 ``-1`` 并设置错误。"
#: ../../c-api/subinterpreters.rst:351
msgid "The caller must have an :term:`attached thread state`."
msgstr "调用方必须有已附加的线程状态 :term:`attached thread state`。"
#: ../../c-api/subinterpreters.rst:358
msgid ""
"Return a dictionary in which interpreter-specific data may be stored. If "
"this function returns ``NULL`` then no exception has been raised and the "
"caller should assume no interpreter-specific dict is available."
msgstr "返回一个存储解释器专属数据的字典。如果此函数返回 ``NULL`` 则没有任何异常被引发并且调用方应当将解释器专属字典视为不可用。"
#: ../../c-api/subinterpreters.rst:362
msgid ""
"This is not a replacement for :c:func:`PyModule_GetState()`, which "
"extensions should use to store interpreter-specific state information."
msgstr "这不是 :c:func:`PyModule_GetState()` 的替代,扩展仍应使用它来存储解释器专属的状态信息。"
#: ../../c-api/subinterpreters.rst:365
msgid ""
"The returned dictionary is borrowed from the interpreter and is valid until "
"interpreter shutdown."
msgstr "返回的字典是从解释器借入的并将保持可用直到解释器关闭。"
#: ../../c-api/subinterpreters.rst:373
msgid "Type of a frame evaluation function."
msgstr "帧评估函数的类型"
#: ../../c-api/subinterpreters.rst:375
msgid ""
"The *throwflag* parameter is used by the ``throw()`` method of generators: "
"if non-zero, handle the current exception."
msgstr "*throwflag* 形参将由生成器的 ``throw()`` 方法来使用:如为非零值,则处理当前异常。"
#: ../../c-api/subinterpreters.rst:378
msgid "The function now takes a *tstate* parameter."
msgstr "此函数现在可接受一个 *tstate* 形参。"
#: ../../c-api/subinterpreters.rst:381
msgid ""
"The *frame* parameter changed from ``PyFrameObject*`` to "
"``_PyInterpreterFrame*``."
msgstr "*frame* 形参由 ``PyFrameObject*`` 改为 ``_PyInterpreterFrame*``。"
#: ../../c-api/subinterpreters.rst:387
msgid "Get the frame evaluation function."
msgstr "获取帧评估函数。"
#: ../../c-api/subinterpreters.rst:389 ../../c-api/subinterpreters.rst:398
msgid "See the :pep:`523` \"Adding a frame evaluation API to CPython\"."
msgstr "请参阅 :pep:`523` \"Adding a frame evaluation API to CPython\"。"
#: ../../c-api/subinterpreters.rst:396
msgid "Set the frame evaluation function."
msgstr "设置帧评估函数。"
#: ../../c-api/subinterpreters.rst:404
msgid "Low-level APIs"
msgstr "低层级 API"
#: ../../c-api/subinterpreters.rst:406
msgid ""
"All of the following functions must be called after :c:func:`Py_Initialize`."
msgstr "下列所有函数都必须在 :c:func:`Py_Initialize` 之后被调用。"
#: ../../c-api/subinterpreters.rst:408
msgid ""
":c:func:`Py_Initialize()` now initializes the :term:`GIL` and sets an "
":term:`attached thread state`."
msgstr ""
"现在 :c:func:`Py_Initialize()` 会初始化 :term:`GIL` 并设置一个 :term:`attached thread "
"state` 线程状态。"
#: ../../c-api/subinterpreters.rst:415
msgid ""
"Create a new interpreter state object. An :term:`attached thread state` is "
"not needed, but may optionally exist if it is necessary to serialize calls "
"to this function."
msgstr ""
"新建一个解释器状态对象。不需要有 :term:`attached thread state`,但如果有必要序列化对此函数的调用则可能选择有。"
#: ../../c-api/subinterpreters.rst:419
msgid ""
"Raises an :ref:`auditing event <auditing>` "
"``cpython.PyInterpreterState_New`` with no arguments."
msgstr "引发一个不带参数的 :ref:`审计事件 <auditing>` ``cpython.PyInterpreterState_New``。"
#: ../../c-api/subinterpreters.rst:424
msgid ""
"Reset all information in an interpreter state object. There must be an "
":term:`attached thread state` for the interpreter."
msgstr "重置解释器状态对象中的所有信息。解释器必须存在一个 :term:`attached thread state`。"
#: ../../c-api/subinterpreters.rst:427
msgid ""
"Raises an :ref:`auditing event <auditing>` "
"``cpython.PyInterpreterState_Clear`` with no arguments."
msgstr ""
"引发一个不带参数的 :ref:`审计事件 <auditing>` ``cpython.PyInterpreterState_Clear``。"
#: ../../c-api/subinterpreters.rst:432
msgid ""
"Destroy an interpreter state object. There **should not** be an "
":term:`attached thread state` for the target interpreter. The interpreter "
"state must have been reset with a previous call to "
":c:func:`PyInterpreterState_Clear`."
msgstr ""
"销毁一个解释器状态对象。目标解释器 **不应** 存在 :term:`attached thread state`。在调用此函数之前,必须先调用 "
":c:func:`PyInterpreterState_Clear` 重置解释器状态。"
#: ../../c-api/subinterpreters.rst:440
msgid "Advanced debugger support"
msgstr ""
#: ../../c-api/subinterpreters.rst:442
msgid ""
"These functions are only intended to be used by advanced debugging tools."
msgstr "这些函数仅供高级调试工具使用。"
#: ../../c-api/subinterpreters.rst:447
msgid ""
"Return the interpreter state object at the head of the list of all such "
"objects."
msgstr "返回由所有此类对象组成的列表中位于开头的解释器状态对象。"
#: ../../c-api/subinterpreters.rst:452
msgid "Return the main interpreter state object."
msgstr "返回主解释器状态对象。"
#: ../../c-api/subinterpreters.rst:457
msgid ""
"Return the next interpreter state object after *interp* from the list of all"
" such objects."
msgstr "从由解释器状态对象组成的列表中返回 *interp* 之后的下一项。"
#: ../../c-api/subinterpreters.rst:463
msgid ""
"Return the pointer to the first :c:type:`PyThreadState` object in the list "
"of threads associated with the interpreter *interp*."
msgstr "在由与解释器 *interp* 相关联的线程组成的列表中返回指向第一个 :c:type:`PyThreadState` 对象的指针。"
#: ../../c-api/subinterpreters.rst:469
msgid ""
"Return the next thread state object after *tstate* from the list of all such"
" objects belonging to the same :c:type:`PyInterpreterState` object."
msgstr ""
"从由属于同一个 :c:type:`PyInterpreterState` 对象的线程状态对象组成的列表中返回 *tstate* 之后的下一项。"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "module"
msgstr "module"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "builtins"
msgstr "builtins"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "__main__"
msgstr "__main__"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "sys"
msgstr "sys"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "stdout (in module sys)"
msgstr "stdout (在 sys 模块中)"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "stderr (in module sys)"
msgstr "stderr (在 sys 模块中)"
#: ../../c-api/subinterpreters.rst:115 ../../c-api/subinterpreters.rst:215
msgid "stdin (in module sys)"
msgstr "stdin (在 sys 模块中)"
#: ../../c-api/subinterpreters.rst:179 ../../c-api/subinterpreters.rst:233
msgid "Py_FinalizeEx (C function)"
msgstr "Py_FinalizeEx (C 函数)"
#: ../../c-api/subinterpreters.rst:179
msgid "Py_Initialize (C function)"
msgstr "Py_Initialize (C 函数)"
#: ../../c-api/subinterpreters.rst:210
msgid "close (in module os)"
msgstr "close (在 os 模块中)"