FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docs-ja/c-api/threads.po at 3.14 · python/python-docs-ja · GitHub
python
python-docs-ja
Repository navigation
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docs-ja
/
c-api
/
threads.po
Copy path
More file actions
More file actions
Latest commit
History
History
History
1767 lines (1554 loc) · 83.3 KB
Breadcrumbs
python-docs-ja
/
c-api
/
threads.po
Copy path
File metadata and controls
1767 lines (1554 loc) · 83.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
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:
#
python-doc bot, 2026
#
#,
fuzzy
msgid ""
msgstr ""
"
Project-Id-Version
:
Python 3.15\n
"
"
Report-Msgid-Bugs-To
:
\n
"
"
POT-Creation-Date
:
2026-10-13 19:59+0000\n
"
"
PO-Revision-Date
:
2026-02-25 14:46+0000\n
"
"
Last-Translator
:
python-doc bot, 2026\n
"
"
Language-Team
:
Japanese (https://app.transifex.com/python-doc/teams/5390/
"
"
ja/)\n
"
"
Language
:
ja\n
"
"
MIME-Version
:
1.0\n
"
"
Content-Type
:
text/plain; charset=UTF-8\n
"
"
Content-Transfer-Encoding
:
8bit\n
"
"
Plural-Forms
:
nplurals=1; plural=0;\n
"
msgid
"Thread states and the global interpreter lock"
msgstr
"スレッド状態とグローバルインタープリタロック"
msgid
""
"Unless on a :term:`free-threaded build` of :term:`CPython`, the Python "
"interpreter is generally not thread-safe. In order to support multi-"
"threaded Python programs, there's a global lock, called the :term:`global "
"interpreter lock` or :term:`GIL`, that must be held by a thread before "
"accessing Python objects. Without the lock, even the simplest operations "
"could cause problems in a multi-threaded program: for example, when two "
"threads simultaneously increment the reference count of the same object, the "
"reference count could end up being incremented only once instead of twice."
msgstr
""
":term:`CPython` の :term:`フリースレッドビルド <free-threaded build>` を除"
"き、Python インタープリタは一般にスレッドセーフではありません。\n"
"マルチスレッドの Python プログラムをサポートするため、:term:`グローバルイン"
"タープリタロック <global interpreter lock>`、または :term:`GIL` というグロー"
"バルなロックがあります。\n"
"スレッドは Python オブジェクトにアクセスする前に、このロックを保持していなけ"
"ればなりません。\n"
"ロックがなければ、マルチスレッドのプログラムでは単純な操作でも問題が起こりえ"
"ます。\n"
"例えば、2 つのスレッドが同じオブジェクトの参照カウントを同時に増やすと、2 回"
"ではなく 1 回しか増えない可能性があります。"
msgid
""
"As such, only a thread that holds the GIL may operate on Python objects or "
"invoke Python's C API."
msgstr
""
"このため、Python オブジェクトの操作や Python の C API の呼び出しを行えるの"
"は、GIL を保持するスレッドだけです。"
msgid
""
"In order to emulate concurrency, the interpreter regularly tries to switch "
"threads between bytecode instructions (see :func:`sys.setswitchinterval`). "
"This is why locks are also necessary for thread-safety in pure-Python code."
msgstr
""
"並行実行を模倣するため、インタープリタはバイトコード命令の間で定期的にスレッ"
"ドの切り替えを試みます (:func:`sys.setswitchinterval` を参照)。\n"
"そのため、純粋な Python コードでもスレッドセーフにするにはロックが必要です。"
msgid
""
"Additionally, the global interpreter lock is released around blocking I/O "
"operations, such as reading or writing to a file. From the C API, this is "
"done by :ref:`detaching the thread state <detaching-thread-state>`."
msgstr
""
"また、ファイルの読み書きなどのブロッキング I/O 操作の間は、グローバルインター"
"プリタロックが解放されます。\n"
"C API では :ref:`スレッド状態をデタッチする <detaching-thread-state>` ことで"
"行います。"
msgid
""
"The Python interpreter keeps some thread-local information inside a data "
"structure called :c:type:`PyThreadState`, known as a :term:`thread state`. "
"Each thread has a thread-local pointer to a :c:type:`PyThreadState`; a "
"thread state referenced by this pointer is considered to be :term:`attached "
"<attached thread state>`."
msgstr
""
"Python インタープリタは、:term:`スレッド状態 <thread state>` と呼ばれる :c:"
"type:`PyThreadState` データ構造に、スレッドごとの情報を保持します。\n"
"各スレッドには :c:type:`PyThreadState` へのスレッドローカルなポインターがあり"
"ます。\n"
"このポインターが参照するスレッド状態は、:term:`アタッチされている <attached "
"thread state>` と見なされます。"
msgid
""
"A thread can only have one :term:`attached thread state` at a time. An "
"attached thread state is typically analogous with holding the GIL, except on "
"free-threaded builds. On builds with the GIL enabled, attaching a thread "
"state will block until the GIL can be acquired. However, even on builds with "
"the GIL disabled, it is still required to have an attached thread state, as "
"the interpreter needs to keep track of which threads may access Python "
"objects."
msgstr
""
"1 つのスレッドが同時に持てる :term:`アタッチされたスレッド状態 <attached "
"thread state>` は 1 つだけです。\n"
"フリースレッドビルドを除けば、スレッド状態がアタッチされていることは通常、"
"GIL を保持していることに相当します。\n"
"GIL が有効なビルドでは、スレッド状態のアタッチは GIL を取得できるまでブロック"
"します。\n"
"ただし、GIL が無効なビルドでも、スレッド状態をアタッチしておく必要がありま"
"す。\n"
"インタープリタが、どのスレッドが Python オブジェクトにアクセスしうるかを把握"
"するためです。"
msgid
""
"Even on the free-threaded build, attaching a thread state may block, as the "
"GIL can be re-enabled or threads might be temporarily suspended (such as "
"during a garbage collection)."
msgstr
""
"フリースレッドビルドでも、スレッド状態のアタッチがブロックすることがありま"
"す。\n"
"GIL が再び有効になる場合や、ガベージコレクション中などにスレッドが一時停止す"
"る場合があるためです。"
msgid
""
"Generally, there will always be an attached thread state when using Python's "
"C API, including during embedding and when implementing methods, so it's "
"uncommon to need to set up a thread state on your own. Only in some specific "
"cases, such as in a :c:macro:`Py_BEGIN_ALLOW_THREADS` block or in a fresh "
"thread, will the thread not have an attached thread state. If uncertain, "
"check if :c:func:`PyThreadState_GetUnchecked` returns ``NULL``."
msgstr
""
"一般に、Python の C API を使うときは、組み込みやメソッドの実装を含め、常にス"
"レッド状態がアタッチされています。\n"
"そのため、自分でスレッド状態を用意する必要はほとんどありません。\n"
"スレッド状態がアタッチされていないのは、:c:macro:`Py_BEGIN_ALLOW_THREADS` ブ"
"ロック内や新しく作られたスレッドなど、特定の場合だけです。\n"
"不確かな場合は、:c:func:`PyThreadState_GetUnchecked` が ``NULL`` を返すかどう"
"かを確認してください。"
msgid
""
"If it turns out that you do need to create a thread state, it is recommended "
"to use :c:func:`PyThreadState_Ensure` or :c:func:"
"`PyThreadState_EnsureFromView`, which will manage the thread state for you."
msgstr
""
"スレッド状態を作成する必要がある場合は、:c:func:`PyThreadState_Ensure` また"
"は :c:func:`PyThreadState_EnsureFromView` を使うことを推奨します。\n"
"これらの関数がスレッド状態を管理します。"
msgid
"Detaching the thread state from extension code"
msgstr
"拡張コードからのスレッド状態のデタッチ"
msgid
""
"Most extension code manipulating the :term:`thread state` has the following "
"simple structure::"
msgstr
""
":term:`スレッド状態 <thread state>` を操作する拡張コードの多くは、次の単純な"
"構造を取ります。 ::"
msgid
""
"Save the thread state in a local variable.\n"
"... Do some blocking I/O operation ...\n"
"Restore the thread state from the local variable."
msgstr
""
"// スレッド状態をローカル変数に保存する。\n"
"// ... ブロッキング I/O 操作を行う ...\n"
"// ローカル変数からスレッド状態を復元する。"
#:
../../c-api/threads.rst:81
msgid
"This is so common that a pair of macros exists to simplify it::"
msgstr
""
"この構造は非常に一般的なので、作業を単純にするために2つのマクロが用意されてい"
"ます::"
msgid
""
"Py_BEGIN_ALLOW_THREADS\n"
"... Do some blocking I/O operation ...\n"
"Py_END_ALLOW_THREADS"
msgstr
""
"Py_BEGIN_ALLOW_THREADS\n"
"... ブロッキング I/O 操作を行う ...\n"
"Py_END_ALLOW_THREADS"
#:
../../c-api/threads.rst:91
msgid
""
"The :c:macro:`Py_BEGIN_ALLOW_THREADS` macro opens a new block and declares a "
"hidden local variable; the :c:macro:`Py_END_ALLOW_THREADS` macro closes the "
"block."
msgstr
""
":c:macro:`Py_BEGIN_ALLOW_THREADS` マクロは新たなブロックを開始し、隠しローカ"
"ル変数を宣言します; :c:macro:`Py_END_ALLOW_THREADS` はブロックを閉じます。"
#:
../../c-api/threads.rst:95
msgid
"The block above expands to the following code::"
msgstr
"上のブロックは次のコードに展開されます::"
msgid
""
"PyThreadState *_save;\n"
"\n"
"_save = PyEval_SaveThread();\n"
"... Do some blocking I/O operation ...\n"
"PyEval_RestoreThread(_save);"
msgstr
""
"PyThreadState *_save;\n"
"\n"
"_save = PyEval_SaveThread();\n"
"... ブロッキング I/O 操作を行う ...\n"
"PyEval_RestoreThread(_save);"
msgid
"Here is how these functions work:"
msgstr
"これらの関数は次のように動作します。"
msgid
""
"The attached thread state implies that the GIL is held for the interpreter. "
"To detach it, :c:func:`PyEval_SaveThread` is called and the result is stored "
"in a local variable."
msgstr
""
"スレッド状態がアタッチされているということは、そのインタープリタの GIL を保持"
"しているということです。\n"
"デタッチするには :c:func:`PyEval_SaveThread` を呼び出し、結果をローカル変数に"
"保存します。"
msgid
""
"By detaching the thread state, the GIL is released, which allows other "
"threads to attach to the interpreter and execute while the current thread "
"performs blocking I/O. When the I/O operation is complete, the old thread "
"state is reattached by calling :c:func:`PyEval_RestoreThread`, which will "
"wait until the GIL can be acquired."
msgstr
""
"スレッド状態をデタッチすると GIL が解放され、現在のスレッドがブロッキング I/"
"O を行っている間に、ほかのスレッドがインタープリタにアタッチして実行できるよ"
"うになります。\n"
"I/O 操作が完了したら、:c:func:`PyEval_RestoreThread` を呼び出して元のスレッド"
"状態を再びアタッチします。\n"
"この呼び出しは GIL を取得できるまで待機します。"
msgid
""
"Performing blocking I/O is the most common use case for detaching the thread "
"state, but it is also useful to call it over long-running native code that "
"doesn't need access to Python objects or Python's C API. For example, the "
"standard :mod:`zlib` and :mod:`hashlib` modules detach the :term:`thread "
"state <attached thread state>` when compressing or hashing data."
msgstr
""
"スレッド状態をデタッチする最も一般的な用途はブロッキング I/O ですが、Python "
"オブジェクトや Python の C API にアクセスしない、実行時間の長いネイティブコー"
"ドでも有用です。\n"
"例えば、標準モジュールの :mod:`zlib` と :mod:`hashlib` は、データの圧縮やハッ"
"シュ計算中に :term:`スレッド状態 <attached thread state>` をデタッチします。"
msgid
""
"On a :term:`free-threaded build`, the :term:`GIL` is usually out of the "
"question, but **detaching the thread state is still required**, because the "
"interpreter periodically needs to block all threads to get a consistent view "
"of Python objects without the risk of race conditions. For example, CPython "
"currently suspends all threads for a short period of time while running the "
"garbage collector."
msgstr
""
":term:`フリースレッドビルド <free-threaded build>` では通常 :term:`GIL` を考"
"慮する必要はありませんが、**スレッド状態のデタッチは依然として必要です**。\n"
"インタープリタは、競合状態の危険なく Python オブジェクトの整合した状態を把握"
"するため、定期的にすべてのスレッドをブロックする必要があるためです。\n"
"例えば、現在の CPython はガベージコレクターの実行中、すべてのスレッドを短時間"
"停止します。"
msgid
""
"Detaching the thread state can lead to unexpected behavior during "
"interpreter finalization. See :ref:`cautions-regarding-runtime-finalization` "
"for more details."
msgstr
""
"スレッド状態のデタッチは、インタープリタの終了処理中に予期しない動作を引き起"
"こす可能性があります。\n"
"詳しくは :ref:`cautions-regarding-runtime-finalization` を参照してください。"
msgid
"APIs"
msgstr
"API"
#:
../../c-api/threads.rst:144
msgid
""
"The following macros are normally used without a trailing semicolon; look "
"for example usage in the Python source distribution."
msgstr
""
"以下のマクロは、通常末尾にセミコロンを付けずに使います; Python ソース配布物内"
"の使用例を見てください。"
msgid
""
"These macros are still necessary on the :term:`free-threaded build` to "
"prevent deadlocks."
msgstr
""
"これらのマクロは、デッドロックを防ぐために :term:`フリースレッドビルド <free-"
"threaded build>` でも必要です。"
#:
../../c-api/threads.rst:154
msgid
""
"This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();"
"``. Note that it contains an opening brace; it must be matched with a "
"following :c:macro:`Py_END_ALLOW_THREADS` macro. See above for further "
"discussion of this macro."
msgstr
""
"このマクロを展開すると ``{ PyThreadState *_save; _save = PyEval_SaveThread();"
"`` になります。マクロに開き波括弧が入っていることに注意してください; この波括"
"弧は後で :c:macro:`Py_END_ALLOW_THREADS` マクロと対応させなければなりません。"
"マクロについての詳しい議論は上記を参照してください。"
msgid
""
"This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it "
"contains a closing brace; it must be matched with an earlier :c:macro:"
"`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of this "
"macro."
msgstr
""
"このマクロを展開すると ``PyEval_RestoreThread(_save); }`` になります。\n"
"閉じ波括弧を含むため、事前の :c:macro:`Py_BEGIN_ALLOW_THREADS` マクロと対応さ"
"せなければなりません。\n"
"このマクロについては上の説明を参照してください。"
#:
../../c-api/threads.rst:170
msgid
""
"This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to :"
"c:macro:`Py_END_ALLOW_THREADS` without the closing brace."
msgstr
""
"このマクロを展開すると ``PyEval_RestoreThread(_save);`` になります: 閉じ波括"
"弧のない :c:macro:`Py_END_ALLOW_THREADS` と同じです。"
#:
../../c-api/threads.rst:176
msgid
""
"This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to :"
"c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable "
"declaration."
msgstr
""
"このマクロを展開すると ``_save = PyEval_SaveThread();`` になります: 開き波括"
"弧のない :c:macro:`Py_BEGIN_ALLOW_THREADS` と同じです。"
msgid
"Using the C API from foreign threads"
msgstr
"外部スレッドからの C API の使用"
msgid
""
"When threads are created using the dedicated Python APIs (such as the :mod:"
"`threading` module), a thread state is automatically associated with them, "
"However, when a thread is created from native code (for example, by a third-"
"party library with its own thread management), it doesn't hold an attached "
"thread state."
msgstr
""
":mod:`threading` モジュールなどの Python の専用 API でスレッドを作成すると、"
"スレッド状態が自動的に関連付けられます。\n"
"一方、独自のスレッド管理を行うサードパーティーライブラリなど、ネイティブコー"
"ドで作成されたスレッドには、アタッチされたスレッド状態がありません。"
msgid
""
"If you need to call Python code from these threads (often this will be part "
"of a callback API provided by the aforementioned third-party library), you "
"must first register these threads with the interpreter by creating a new "
"thread state and attaching it."
msgstr
""
"このようなスレッドから Python コードを呼び出す必要がある場合は、まずスレッド"
"状態を新しく作成してアタッチし、スレッドをインタープリタに登録しなければなり"
"ません。\n"
"このような呼び出しは、前述のサードパーティーライブラリが提供するコールバック "
"API の一部として行われることがよくあります。"
msgid
""
"The easiest way to do this is through :c:func:`PyThreadState_Ensure` or :c:"
"func:`PyThreadState_EnsureFromView`."
msgstr
""
"最も簡単な方法は、:c:func:`PyThreadState_Ensure` または :c:func:"
"`PyThreadState_EnsureFromView` を使うことです。"
msgid
""
"These functions require an argument pointing to the desired interpreter; "
"such a pointer can be acquired via a call to :c:func:"
"`PyInterpreterGuard_FromCurrent` (for ``PyThreadState_Ensure``) or :c:func:"
"`PyInterpreterView_FromCurrent` (for ``PyThreadState_EnsureFromView``) from "
"the function that creates the thread. If no pointer is available (such as "
"when the given native thread library doesn't provide a data argument), :c:"
"func:`PyInterpreterView_FromMain` can be used to get a view for the main "
"interpreter, but note that this will make the code incompatible with "
"subinterpreters."
msgstr
""
"これらの関数には、対象のインタープリタを指すポインターを引数として渡す必要が"
"あります。\n"
"このポインターは、スレッドを作成する関数で :c:func:"
"`PyInterpreterGuard_FromCurrent` (``PyThreadState_Ensure`` 用) または :c:"
"func:`PyInterpreterView_FromCurrent` (``PyThreadState_EnsureFromView`` 用) を"
"呼び出すことで取得できます。\n"
"ネイティブスレッドライブラリにデータを渡す引数がない場合など、ポインターを利"
"用できないときは、:c:func:`PyInterpreterView_FromMain` でメインインタープリタ"
"のビューを取得できます。\n"
"ただし、この方法ではコードがサブインタープリタに対応できなくなることに注意し"
"てください。"
#:
../../c-api/threads.rst:214
msgid
"For example::"
msgstr
"例えば::"
msgid
""
"// The return value of PyInterpreterGuard_FromCurrent() from the\n"
"// function that created this thread.\n"
"PyInterpreterGuard *guard = thread_data->guard;\n"
"\n"
"// Create a new thread state for the interpreter.\n"
"PyThreadStateToken *token = PyThreadState_Ensure(guard);\n"
"if (token == NULL) {\n"
" PyInterpreterGuard_Close(guard);\n"
" return;\n"
"}\n"
"\n"
"// We have a valid thread state -- perform Python actions here.\n"
"result = CallSomeFunction();\n"
"// Evaluate result or handle exceptions.\n"
"\n"
"// Release the thread state. No calls to the C API are allowed beyond this\n"
"// point.\n"
"PyThreadState_Release(token);\n"
"PyInterpreterGuard_Close(guard);"
msgstr
""
"// このスレッドを作成した関数での\n"
"// PyInterpreterGuard_FromCurrent() の戻り値。\n"
"PyInterpreterGuard *guard = thread_data->guard;\n"
"\n"
"// インタープリタのスレッド状態を新しく作成する。\n"
"PyThreadStateToken *token = PyThreadState_Ensure(guard);\n"
"if (token == NULL) {\n"
" PyInterpreterGuard_Close(guard);\n"
" return;\n"
"}\n"
"\n"
"// 有効なスレッド状態があるので、ここで Python の操作を行う。\n"
"result = CallSomeFunction();\n"
"// result を評価するか、例外を処理する。\n"
"\n"
"// スレッド状態を解放する。\n"
"// ここから先では C API を呼び出してはならない。\n"
"PyThreadState_Release(token);\n"
"PyInterpreterGuard_Close(guard);"
msgid
""
"Keep in mind that calling ``PyThreadState_Ensure`` might not always create a "
"new thread state, and calling ``PyThreadState_Release`` might not always "
"detach it. These functions may reuse an existing attached thread state, or "
"may re-attach a thread state that was previously attached for the current "
"thread."
msgstr
""
"``PyThreadState_Ensure`` を呼び出しても、必ずしもスレッド状態が新しく作成され"
"るとは限りません。\n"
"また、``PyThreadState_Release`` を呼び出しても、必ずしもデタッチされるとは限"
"りません。\n"
"これらの関数は、すでにアタッチされたスレッド状態を再利用したり、現在のスレッ"
"ドに以前アタッチされていたスレッド状態を再びアタッチしたりする場合がありま"
"す。"
msgid
":pep:`788`"
msgstr
":pep:`788`"
msgid
"Reusing a thread state across repeated calls"
msgstr
"繰り返しの呼び出しでスレッド状態を再利用する"
msgid
""
"Creating and destroying a :c:type:`PyThreadState` is not free, and is more "
"expensive on a :term:`free-threaded build`. A foreign thread that calls "
"into the interpreter many times -- for example, a worker thread in a native "
"thread pool -- should avoid creating a fresh thread state on every entry and "
"destroying it on every exit. Instead, set up one thread state when the "
"thread starts (or lazily on its first call into Python), attach and detach "
"it around each call, and tear it down once when the thread exits."
msgstr
""
":c:type:`PyThreadState` の作成と破棄にはコストがかかり、:term:`フリースレッド"
"ビルド <free-threaded build>` ではさらに高くなります。\n"
"ネイティブのスレッドプールのワーカースレッドなど、インタープリタを何度も呼び"
"出す外部スレッドでは、呼び出しのたびにスレッド状態を作成し、戻るたびに破棄す"
"ることを避けるべきです。\n"
"代わりに、スレッドの開始時、または最初に Python を呼び出したときにスレッド状"
"態を 1 つ用意し、各呼び出しの前後でアタッチとデタッチを行い、スレッドの終了時"
"に一度だけ破棄します。"
msgid
""
"Manage the thread state explicitly with :c:func:`PyThreadState_New`, "
"attaching and detaching it with :c:func:`PyEval_RestoreThread` and :c:func:"
"`PyEval_SaveThread`. This happens in three distinct phases, at different "
"points in the thread's life."
msgstr
""
":c:func:`PyThreadState_New` でスレッド状態を明示的に管理し、:c:func:"
"`PyEval_RestoreThread` と :c:func:`PyEval_SaveThread` でアタッチとデタッチを"
"行います。\n"
"この処理は、スレッドのライフサイクルの異なる時点で行う、3 つの段階に分かれま"
"す。"
msgid
""
"When the thread starts, create one thread state for it. ``interp`` is the "
"target interpreter, captured by the code that created this thread while it "
"held an attached thread state (for example via :c:func:"
"`PyInterpreterState_Get`)::"
msgstr
""
"スレッドの開始時に、そのスレッドのスレッド状態を 1 つ作成します。\n"
"``interp`` は対象のインタープリタです。\n"
"スレッドを作成したコードが、スレッド状態をアタッチした状態で :c:func:"
"`PyInterpreterState_Get` などを呼び出して取得しておきます。 ::"
msgid
"PyThreadState *tstate = PyThreadState_New(interp);"
msgstr
"PyThreadState *tstate = PyThreadState_New(interp);"
msgid
""
"Then, on each call into Python -- which may happen many times over the "
"thread's life -- attach the thread state, make the Python C API calls that "
"require it, and detach again so the thread does not hold the GIL while off "
"doing non-Python work::"
msgstr
""
"その後、Python を呼び出すたびにスレッド状態をアタッチし、その状態を必要とす"
"る Python C API を呼び出してから、再びデタッチします。\n"
"こうすることで、Python 以外の処理中にスレッドが GIL を保持しないようにしま"
"す。\n"
"Python の呼び出しは、スレッドの存続中に何度も行われる場合があります。 ::"
msgid
""
"PyEval_RestoreThread(tstate);\n"
"result = CallSomeFunction(); /* your Python C API calls go here */\n"
"PyEval_SaveThread();"
msgstr
""
"PyEval_RestoreThread(tstate);\n"
"result = CallSomeFunction(); /* ここで Python C API を呼び出す */\n"
"PyEval_SaveThread();"
msgid
""
"When the thread is finished calling into Python, destroy the thread state "
"once::"
msgstr
""
"スレッドが Python を呼び出す必要がなくなったら、スレッド状態を一度だけ破棄し"
"ます。 ::"
msgid
""
"PyEval_RestoreThread(tstate);\n"
"PyThreadState_Clear(tstate);\n"
"PyThreadState_DeleteCurrent();"
msgstr
""
"PyEval_RestoreThread(tstate);\n"
"PyThreadState_Clear(tstate);\n"
"PyThreadState_DeleteCurrent();"
msgid
""
"The general-purpose entry points for calling in from a foreign thread -- :c:"
"func:`PyThreadState_Ensure` and the older :c:func:`PyGILState_Ensure` -- do "
"*not* guarantee a persistent thread state: their thread-state lifetime is "
"deliberately implementation-defined, so a matched acquire/release pair may "
"create and destroy a thread state each time. Use :c:func:"
"`PyThreadState_New`, as shown here, whenever you specifically want to reuse "
"one thread state across calls."
msgstr
""
"外部スレッドからの呼び出しに使う汎用の関数 :c:func:`PyThreadState_Ensure` "
"と、従来の :c:func:`PyGILState_Ensure` は、スレッド状態が保持されることを保"
"証 *しません*。\n"
"スレッド状態の寿命は意図的に実装に委ねられているため、対応する取得と解放の組"
"ごとにスレッド状態が作成・破棄される場合があります。\n"
"呼び出しをまたいで 1 つのスレッド状態を再利用したい場合は、ここに示したよう"
"に :c:func:`PyThreadState_New` を使ってください。"
msgid
""
"The code that created the foreign thread must arrange for the shutdown "
"sequence to run before the thread exits, and before :c:func:`Py_FinalizeEx` "
"is called. If interpreter finalization begins first, the shutdown :c:func:"
"`PyEval_RestoreThread` call will hang the thread rather than return (see :"
"ref:`cautions-regarding-runtime-finalization`). If the thread exits without "
"running the shutdown sequence, the thread state is leaked for the remainder "
"of the process."
msgstr
""
"外部スレッドを作成したコードは、スレッドが終了する前、かつ :c:func:"
"`Py_FinalizeEx` が呼び出される前に、後始末の手順が実行されるようにしなければ"
"なりません。\n"
"インタープリタの終了処理が先に始まると、後始末で呼び出す :c:func:"
"`PyEval_RestoreThread` は戻らずにスレッドを停止させます (:ref:`cautions-"
"regarding-runtime-finalization` を参照)。\n"
"後始末を行わずにスレッドが終了すると、スレッド状態はプロセスの終了までリーク"
"したままになります。"
msgid
"Attaching/detaching thread states"
msgstr
"スレッド状態のアタッチとデタッチ"
msgid
""
"Ensure that the thread has an attached thread state for the interpreter "
"protected by *guard*, and thus can safely invoke that interpreter."
msgstr
""
"スレッドに、*guard* が保護するインタープリタのスレッド状態をアタッチし、その"
"インタープリタを安全に呼び出せるようにします。"
msgid
""
"It is OK to call this function if the thread already has an attached thread "
"state, as long as there is a subsequent call to :c:func:"
"`PyThreadState_Release` that matches this one (meaning that
\"
nested
\"
calls "
"to this function are permitted)."
msgstr
""
"すでにスレッド状態がアタッチされているスレッドから呼び出しても構いません。\n"
"ただし、この呼び出しに対応する :c:func:`PyThreadState_Release` を後で呼び出す"
"必要があります (つまり、この関数の入れ子の呼び出しは許可されています)。"
msgid
""
"The function's effect (if any) will be reversed by the matching call to :c:"
"func:`PyThreadState_Release`."
msgstr
""
"この関数が状態を変更した場合、対応する :c:func:`PyThreadState_Release` の呼び"
"出しによって元に戻ります。"
msgid
""
"On error, this function returns ``NULL`` *without* an exception set. Do not "
"call :c:func:`!PyThreadState_Release` in this case."
msgstr
""
"エラー時は、例外を設定 *せずに* ``NULL`` を返します。\n"
"この場合は :c:func:`!PyThreadState_Release` を呼び出さないでください。"
msgid
""
"On success, this function returns a pointer value that must be passed to the "
"matching call to :c:func:`!PyThreadState_Release`."
msgstr
""
"成功時はポインター値を返します。\n"
"この値は、対応する :c:func:`!PyThreadState_Release` の呼び出しに渡さなければ"
"なりません。"
msgid
""
"The conditions in which this function creates a new :term:`thread state` are "
"considered unstable and implementation-dependent. If you need to control the "
"exact lifetime of a thread state, consider using :c:func:"
"`PyThreadState_New`. However, do not avoid this function solely on the basis "
"that the lifetime of the thread state may be inconsistent across versions; "
"changes to this function will be done with caution and in a backwards-"
"compatible manner. In particular, the saving of thread-local variables and "
"similar state will be retained across Python versions."
msgstr
""
"この関数が新しい :term:`スレッド状態 <thread state>` を作成する条件は、安定し"
"た仕様ではなく実装に依存します。\n"
"スレッド状態の寿命を厳密に制御する必要がある場合は、:c:func:"
"`PyThreadState_New` の使用を検討してください。\n"
"ただし、バージョンによってスレッド状態の寿命が異なる可能性があるという理由だ"
"けで、この関数の使用を避けないでください。\n"
"この関数の変更は、後方互換性を保ちながら慎重に行われます。\n"
"特に、スレッドローカル変数や同様の状態の保存は、Python のバージョンが変わって"
"も維持されます。"
msgid
""
"The exact behavior of whether this function creates a new thread state is "
"described below, but be aware that this may change in the future."
msgstr
""
"この関数が新しいスレッド状態を作成するかどうかの具体的な動作を以下に示しま"
"す。\n"
"ただし、将来変わる可能性があることに注意してください。"
msgid
""
"First, this function checks if an attached thread state is present. If there "
"is, this function then checks if the interpreter of that thread state "
"matches the interpreter guarded by *guard*. If that is the case, this "
"function simply marks the thread state as being used by a "
"``PyThreadState_Ensure`` call and returns."
msgstr
""
"まず、アタッチされたスレッド状態があるかどうかを調べます。\n"
"ある場合は、そのスレッド状態のインタープリタが *guard* で保護されたインタープ"
"リタと一致するかを調べます。\n"
"一致すれば、スレッド状態に ``PyThreadState_Ensure`` の呼び出しで使用中である"
"ことを記録して戻ります。"
msgid
""
"If there is no attached thread state, then this function checks if any "
"thread state has been used by the current OS thread. (This is returned by :c:"
"func:`PyGILState_GetThisThreadState`.) If there was, then this function "
"checks if that thread state's interpreter matches *guard*. If it does, it is "
"re-attached and marked as used."
msgstr
""
"アタッチされたスレッド状態がない場合は、現在の OS スレッドが使用したスレッド"
"状態があるかどうかを調べます (:c:func:`PyGILState_GetThisThreadState` が返す"
"ものです)。\n"
"ある場合は、そのスレッド状態のインタープリタが *guard* と一致するかを調べま"
"す。\n"
"一致すれば、再びアタッチして使用中であることを記録します。"
msgid
""
"Otherwise, if both of the above cases fail, a new thread state is created "
"for *guard*. It is then attached and marked as owned by "
"``PyThreadState_Ensure``."
msgstr
""
"上のどちらにも当てはまらない場合は、*guard* 用のスレッド状態を新しく作成しま"
"す。\n"
"その後、そのスレッド状態をアタッチし、``PyThreadState_Ensure`` が所有すること"
"を記録します。"
msgid
"Get an attached thread state for the interpreter referenced by *view*."
msgstr
""
"*view* が参照するインタープリタの、アタッチされたスレッド状態を取得します。"
msgid
""
"The behavior and return value are the same as for :c:func:"
"`PyThreadState_Ensure`; additionally, if the function succeeds, the "
"interpreter referenced by *view* will be implicitly guarded. The guard will "
"be released upon the corresponding :c:func:`PyThreadState_Release` call."
msgstr
""
"動作と戻り値は :c:func:`PyThreadState_Ensure` と同じです。\n"
"さらに、関数が成功した場合は *view* が参照するインタープリタが暗黙に保護され"
"ます。\n"
"この保護は、対応する :c:func:`PyThreadState_Release` の呼び出しで解除されま"
"す。"
msgid
""
"Undo a :c:func:`PyThreadState_Ensure` or :c:func:"
"`PyThreadState_EnsureFromView` call."
msgstr
""
":c:func:`PyThreadState_Ensure` または :c:func:`PyThreadState_EnsureFromView` "
"の呼び出しによる変更を元に戻します。"
msgid
""
"This must be called exactly once for each successful *Ensure* call, with "
"*token* set to that call's return value."
msgstr
""
"成功した *Ensure* の呼び出しごとに、その戻り値を *token* に指定して、必ず一度"
"だけ呼び出さなければなりません。"
msgid
""
"The state that was attached before the corresponding *Ensure* call (if any) "
"will be attached when :c:func:`PyThreadState_Release` returns."
msgstr
""
"対応する *Ensure* の呼び出しの前にスレッド状態がアタッチされていた場合、:c:"
"func:`PyThreadState_Release` が戻るときには、その状態がアタッチされています。"
msgid
""
"The exact behavior of whether this function deletes a thread state is "
"considered unstable and implementation-dependent."
msgstr
""
"この関数がスレッド状態を削除するかどうかの具体的な動作は、安定した仕様ではな"
"く実装に依存します。"
msgid
""
"Currently, this function will decrement an internal counter on the attached "
"thread state. If this counter ever reaches below zero, this function emits a "
"fatal error (via :c:func:`Py_FatalError`)."
msgstr
""
"現在、この関数はアタッチされたスレッド状態の内部カウンターを減らします。\n"
"カウンターがゼロ未満になると、:c:func:`Py_FatalError` によって致命的エラーを"
"発生させます。"
msgid
""
"If the attached thread state is owned by ``PyThreadState_Ensure``, then the "
"attached thread state will be deallocated and deleted upon the internal "
"counter reaching zero. Otherwise, nothing happens when the counter reaches "
"zero."
msgstr
""
"アタッチされたスレッド状態を ``PyThreadState_Ensure`` が所有している場合は、"
"内部カウンターがゼロになるとそのスレッド状態を解放して削除します。\n"
"それ以外の場合は、カウンターがゼロになっても何も起こりません。"
msgid
""
"An opaque token retrieved from a :c:func:`PyThreadState_Ensure` call and "
"passed to a corresponding :c:func:`PyThreadState_Release` call."
msgstr
""
":c:func:`PyThreadState_Ensure` の呼び出しで取得し、対応する :c:func:"
"`PyThreadState_Release` の呼び出しに渡す不透明なトークンです。"
msgid
"GIL-state APIs"
msgstr
"GIL 状態の API"
msgid
""
"The following APIs are generally not compatible with subinterpreters and "
"will hang the process during interpreter finalization (see :ref:`cautions-"
"regarding-runtime-finalization`). As such, these APIs were :term:`soft "
"deprecated` in Python 3.15 in favor of the :ref:`new APIs <c-api-foreign-"
"threads>`."
msgstr
""
"以下の API は一般にサブインタープリタに対応しておらず、インタープリタの終了処"
"理中にはプロセスが停止したままになります (:ref:`cautions-regarding-runtime-"
"finalization` を参照)。\n"
"そのため、Python 3.15 で :term:`緩やかに非推奨 <soft deprecated>` となり、代"
"わりに :ref:`新しい API <c-api-foreign-threads>` の使用を推奨します。"
msgid
""
"The type of the value returned by :c:func:`PyGILState_Ensure` and passed to :"
"c:func:`PyGILState_Release`."
msgstr
""
":c:func:`PyGILState_Ensure` が返し、:c:func:`PyGILState_Release` に渡す値の型"
"です。"
msgid
"The GIL was already held when :c:func:`PyGILState_Ensure` was called."
msgstr
""
":c:func:`PyGILState_Ensure` が呼び出された時点で、すでに GIL を保持していまし"
"た。"
msgid
"The GIL was not held when :c:func:`PyGILState_Ensure` was called."
msgstr
""
":c:func:`PyGILState_Ensure` が呼び出された時点では、GIL を保持していませんで"
"した。"
msgid
""
"Ensure that the current thread is ready to call the Python C API regardless "
"of the current state of Python, or of the :term:`attached thread state`. "
"This may be called as many times as desired by a thread as long as each call "
"is matched with a call to :c:func:`PyGILState_Release`. In general, other "
"thread-related APIs may be used between :c:func:`PyGILState_Ensure` and :c:"
"func:`PyGILState_Release` calls as long as the thread state is restored to "
"its previous state before the Release(). For example, normal usage of the :"
"c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS` macros "
"is acceptable."
msgstr
""
"Python や :term:`アタッチされたスレッド状態 <attached thread state>` の現在の"
"状態にかかわらず、現在のスレッドで Python C API を呼び出せるようにします。\n"
"各呼び出しに対応する :c:func:`PyGILState_Release` を呼び出す限り、スレッドは"
"何度でもこの関数を呼び出せます。\n"
"一般に、:c:func:`PyGILState_Ensure` と :c:func:`PyGILState_Release` の間で"
"は、``Release()`` の前にスレッド状態を元に戻す限り、ほかのスレッド関連の API "
"を使っても構いません。\n"
"例えば、:c:macro:`Py_BEGIN_ALLOW_THREADS` と :c:macro:`Py_END_ALLOW_THREADS` "
"マクロは通常どおり使えます。"
msgid
""
"The return value is an opaque
\"
handle
\"
to the :term:`attached thread "
"state` when :c:func:`PyGILState_Ensure` was called, and must be passed to :c:"
"func:`PyGILState_Release` to ensure Python is left in the same state. Even "
"though recursive calls are allowed, these handles *cannot* be shared - each "
"unique call to :c:func:`PyGILState_Ensure` must save the handle for its call "
"to :c:func:`PyGILState_Release`."
msgstr
""
"戻り値は、:c:func:`PyGILState_Ensure` を呼び出したときの :term:`アタッチされ"
"たスレッド状態 <attached thread state>` を表す不透明な「ハンドル」です。\n"
"Python を同じ状態に戻すため、:c:func:`PyGILState_Release` に渡さなければなり"
"ません。\n"
"再帰的な呼び出しは許可されていますが、ハンドルを共有することは *できません"
"*。\n"
":c:func:`PyGILState_Ensure` の呼び出しごとにハンドルを保存し、その呼び出しに"
"対応する :c:func:`PyGILState_Release` に渡す必要があります。"
msgid
""
"When the function returns, there will be an :term:`attached thread state` "
"and the thread will be able to call arbitrary Python code."
msgstr
""
"この関数が戻るときには :term:`スレッド状態がアタッチされており <attached "
"thread state>`、スレッドは任意の Python コードを呼び出せます。"
msgid
""
"This function has no way to return an error. As such, errors are either "
"fatal (that is, they send ``SIGABRT`` and crash the process; see :c:func:"
"`Py_FatalError`), or the thread will be permanently blocked (such as during "
"interpreter finalization)."
msgstr
""
"この関数にはエラーを返す手段がありません。\n"
"そのため、エラーは致命的エラーとなる (``SIGABRT`` を送信してプロセスを異常終"
"了させる。\n"
":c:func:`Py_FatalError` を参照) か、インタープリタの終了処理中のように、ス"
"レッドが永久にブロックされます。"
msgid
""
"Calling this function when the interpreter is finalizing will infinitely "
"hang the thread, which may cause deadlocks. :ref:`cautions-regarding-runtime-"
"finalization` for more details."
msgstr
""
"インタープリタの終了処理中に呼び出すと、スレッドが無期限に停止し、デッドロッ"
"クの原因になる可能性があります。\n"
"詳しくは :ref:`cautions-regarding-runtime-finalization` を参照してください。"
msgid
""
"In addition, this function generally does not work with subinterpreters when "
"used from foreign threads, because this function has no way of knowing which "
"interpreter created the thread (and as such, will implicitly pick the main "
"interpreter)."
msgstr
""
"また、外部スレッドから使う場合、この関数は一般にサブインタープリタでは動作し"
"ません。\n"
"どのインタープリタがスレッドを作成したかを知る手段がないため、暗黙にメインイ"
"ンタープリタを選ぶからです。"
msgid
""
"Hangs the current thread, rather than terminating it, if called while the "
"interpreter is finalizing."
msgstr
""
"インタープリタの終了処理中に呼び出された場合、現在のスレッドを終了させる代わ"
"りに、停止したままにするようになりました。"
msgid
""
"Use :c:func:`PyThreadState_Ensure` or :c:func:`PyThreadState_EnsureFromView` "
"instead."
msgstr
""
"代わりに :c:func:`PyThreadState_Ensure` または :c:func:"
"`PyThreadState_EnsureFromView` を使ってください。"
msgid
""
"Release any resources previously acquired. After this call, Python's state "
"will be the same as it was prior to the corresponding :c:func:"
"`PyGILState_Ensure` call (but generally this state will be unknown to the "
"caller, hence the use of the GIL-state API)."
msgstr
""
"先に取得したリソースを解放します。\n"
"呼び出し後の Python の状態は、対応する :c:func:`PyGILState_Ensure` の呼び出し"
"の前と同じになります (ただし、呼び出し元は通常その状態を把握していないため、"
"GIL 状態の API を使います)。"
#:
../../c-api/threads.rst:481
msgid
""
"Every call to :c:func:`PyGILState_Ensure` must be matched by a call to :c:"
"func:`PyGILState_Release` on the same thread."
msgstr
""
":c:func:`PyGILState_Ensure` を呼び出す場合は、必ず同一スレッド内で対応する :"
"c:func:`PyGILState_Release` を呼び出してください。"
msgid
"Use :c:func:`PyThreadState_Release` instead."
msgstr
"代わりに :c:func:`PyThreadState_Release` を使ってください。"
msgid
""
"Get the :term:`thread state` that was most recently :term:`attached "
"<attached thread state>` for this thread. (If the most recent thread state "
"has been deleted, this returns ``NULL``.)"
msgstr
""
"このスレッドに最後に :term:`アタッチされた <attached thread state>` :term:`ス"
"レッド状態 <thread state>` を取得します。\n"
"最後のスレッド状態が削除されていれば ``NULL`` を返します。"
msgid
"If the caller has an attached thread state, it is returned."
msgstr
"呼び出し元にアタッチされたスレッド状態があれば、それを返します。"
msgid
""
"In other terms, this function returns the thread state that will be used by :"
"c:func:`PyGILState_Ensure`. If this returns ``NULL``, then "
"``PyGILState_Ensure`` will create a new thread state."
msgstr
""
"言い換えると、:c:func:`PyGILState_Ensure` が使うスレッド状態を返します。\n"
"``NULL`` を返す場合、``PyGILState_Ensure`` はスレッド状態を新しく作成します。"
msgid
"This function cannot fail."
msgstr
"この関数は失敗しません。"
msgid
""
"Use :c:func:`PyThreadState_Get` or :c:func:`PyThreadState_GetUnchecked` "
"instead."
msgstr
""
"代わりに :c:func:`PyThreadState_Get` または :c:func:"
"`PyThreadState_GetUnchecked` を使ってください。"
msgid
""
"Return ``1`` if the current thread has an :term:`attached thread state` that "
"matches the thread state returned by :c:func:"
"`PyGILState_GetThisThreadState`. If the caller has no attached thread state "
"or it otherwise doesn't match, then this returns ``0``."
msgstr
""
"現在のスレッドに :term:`アタッチされたスレッド状態 <attached thread state>` "
"があり、:c:func:`PyGILState_GetThisThreadState` が返すスレッド状態と一致する"
"場合は ``1`` を返します。\n"
"呼び出し元にアタッチされたスレッド状態がない場合や、一致しない場合は ``0`` を"
"返します。"
msgid
""
"If the current Python process has ever created a subinterpreter, this "
"function will *always* return ``1``."
msgstr
""
"現在の Python プロセスが一度でもサブインタープリタを作成していれば、この関数"
"は *常に* ``1`` を返します。"
msgid
"This is mainly a helper/diagnostic function."
msgstr
"主に補助や診断のための関数です。"
msgid
"Use ``PyThreadState_GetUnchecked() != NULL`` instead."
msgstr
"代わりに ``PyThreadState_GetUnchecked() != NULL`` を使ってください。"
msgid
"Cautions about fork()"
msgstr
"fork() に関する注意"
msgid
""
"Another important thing to note about threads is their behaviour in the face "
"of the C :c:func:`fork` call. On most systems with :c:func:`fork`, after a "
"process forks only the thread that issued the fork will exist. This has a "
"concrete impact both on how locks must be handled and on all stored state in "
"CPython's runtime."
msgstr
""
"スレッドに関するもう 1 つの重要な注意点は、C の :c:func:`fork` 呼び出し時の動"
"作です。\n"
":c:func:`fork` を備えるほとんどのシステムでは、プロセスを fork した後には、"
"fork を呼び出したスレッドだけが存在します。\n"
"これは、ロックの扱い方と CPython ランタイムに保存されたすべての状態の両方に、"
"具体的な影響を及ぼします。"
msgid
""
"The fact that only the
\"
current
\"
thread remains means any locks held by "
"other threads will never be released. Python solves this for :func:`os.fork` "
"by acquiring the locks it uses internally before the fork, and releasing "
"them afterwards. In addition, it resets any :ref:`lock-objects` in the "
"child. When extending or embedding Python, there is no way to inform Python "
"of additional (non-Python) locks that need to be acquired before or reset "
"after a fork. OS facilities such as :c:func:`!pthread_atfork` would need to "
"be used to accomplish the same thing. Additionally, when extending or "
"embedding Python, calling :c:func:`fork` directly rather than through :func:"
"`os.fork` (and returning to or calling into Python) may result in a deadlock "
"by one of Python's internal locks being held by a thread that is defunct "
"after the fork. :c:func:`PyOS_AfterFork_Child` tries to reset the necessary "
"locks, but is not always able to."
msgstr
""
"「現在の」スレッドだけが残るため、ほかのスレッドが保持していたロックは解放さ"
"れなくなります。\n"
"Python は :func:`os.fork` で、内部で使うロックを fork の前に取得し、後で解放"
"することで対処します。\n"
"さらに、子プロセスの :ref:`lock-objects` をすべてリセットします。\n"
"Python の拡張や組み込みでは、fork 前の取得や fork 後のリセットが必要な、"
"Python 以外の追加のロックを Python に知らせる方法はありません。\n"
"同じ処理を行うには、:c:func:`!pthread_atfork` などの OS の機能を使う必要があ"
"ります。\n"
"また、Python の拡張や組み込みで :func:`os.fork` を経由せずに :c:func:`fork` "
"を直接呼び出し、その後 Python に戻るか Python を呼び出すと、デッドロックが起"
"こる可能性があります。\n"
"Python 内部のロックを保持していたスレッドが、fork 後には存在しなくなるためで"
"す。\n"
":c:func:`PyOS_AfterFork_Child` は必要なロックのリセットを試みますが、常にでき"
"るとは限りません。"
msgid
""
"The fact that all other threads go away also means that CPython's runtime "
"state there must be cleaned up properly, which :func:`os.fork` does. This "
"means finalizing all other :c:type:`PyThreadState` objects belonging to the "
"current interpreter and all other :c:type:`PyInterpreterState` objects. Due "
"to this and the special nature of the :ref:`
\"
main
\"
interpreter <sub-"
"interpreter-support>`, :c:func:`fork` should only be called in that "
"interpreter's
\"
main
\"
thread, where the CPython global runtime was "
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL