Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127989: C API: Refer to attached thread states instead of the GIL#127990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 76 commits intopython:mainfromZeroIntensity:clarify-gil-tstate
Mar 20, 2025
Merged
Changes from1 commit
Commits
Show all changes
76 commits
Select commitHold shift + click to select a range
ad7ee2d
Document the term 'thread state.'
ZeroIntensityDec 14, 2024
bea045a
Change term for PyDict_GetItem
ZeroIntensityDec 14, 2024
e286ba5
Change term for PyErr_Occurred
ZeroIntensityDec 14, 2024
6006b22
Change term for PyErr_SetInterrupt
ZeroIntensityDec 14, 2024
8dc3928
Change term for PyErr_SetInterruptEx
ZeroIntensityDec 14, 2024
f46ca3d
Change term for PyConfig_Get
ZeroIntensityDec 14, 2024
555a03c
Change term for PyConfig_Names
ZeroIntensityDec 14, 2024
ddb98cd
Change term for PyConfig_Set
ZeroIntensityDec 14, 2024
5d423f8
Change term for PyUnstable_AtExit
ZeroIntensityDec 14, 2024
d2d2f67
Change term for Py_Initialize note
ZeroIntensityDec 14, 2024
aa9c4c6
Change term for PyInterpreterState_Get
ZeroIntensityDec 14, 2024
c05be67
Change term for PyInterpreterState_GetID
ZeroIntensityDec 14, 2024
3a69922
Change term for PyThreadState_SetAsyncEx
ZeroIntensityDec 14, 2024
3336ad7
Change term for Py_NewInterpreterFromConfig
ZeroIntensityDec 14, 2024
3991681
Change term for Py_FinalizeEx
ZeroIntensityDec 14, 2024
6d397eb
Change term for Py_AddPendingCall
ZeroIntensityDec 14, 2024
3b7b3ff
Change term for PyEval_SetProfile
ZeroIntensityDec 14, 2024
5358d14
Change term for PyEval_SetProfileAllThreads
ZeroIntensityDec 14, 2024
093ba05
Change term for PyEval_SetTrace
ZeroIntensityDec 14, 2024
11582fa
Change term for PyEval_SetTraceAllThreads
ZeroIntensityDec 14, 2024
3d55d2d
Change term for PyRefTracer_SetTracer
ZeroIntensityDec 14, 2024
2785c1d
Change term for PyRefTracer_GetTracer
ZeroIntensityDec 14, 2024
6d80b02
Change term for PyMutex_Lock
ZeroIntensityDec 14, 2024
94e046b
Change term for allocator domains
ZeroIntensityDec 14, 2024
713beb2
Change term for raw memory interface
ZeroIntensityDec 14, 2024
2140bde
Change term for memory interface
ZeroIntensityDec 14, 2024
f608211
Change term for object allocators
ZeroIntensityDec 14, 2024
d619387
Change term for PyMem_SetAllocator
ZeroIntensityDec 14, 2024
e7828ed
Change term for PyMem_SetAllocator (again)
ZeroIntensityDec 14, 2024
6b33565
Change term for debug hooks
ZeroIntensityDec 14, 2024
6230177
Change term for debug hooks (again)
ZeroIntensityDec 14, 2024
f74832a
Change term for PyState*
ZeroIntensityDec 14, 2024
7161fc0
Change term for various things
ZeroIntensityDec 14, 2024
d58b74f
Change term for clock functions
ZeroIntensityDec 14, 2024
a761c4a
Change term for raw clock functions
ZeroIntensityDec 14, 2024
de122f5
Change term for tp_dealloc warning
ZeroIntensityDec 14, 2024
0b0176b
Change term for the types tutorial
ZeroIntensityDec 14, 2024
c15f5c4
Add more information about thread states.
ZeroIntensityDec 14, 2024
0130b20
Change terms for 'cautions regarding runtime finalization'
ZeroIntensityDec 14, 2024
a1e47b7
Simplify PyEval_SaveThread and PyEval_RestoreThread
ZeroIntensityDec 14, 2024
0173c46
Some more terminology fixups.
ZeroIntensityDec 14, 2024
166d970
Fix Sphinx build errors.
ZeroIntensityDec 14, 2024
adae494
Change some usage of the term 'global interpreter lock'
ZeroIntensityDec 14, 2024
a70ab11
Add some more terms for disambiguation.
ZeroIntensityDec 14, 2024
8584c86
Change usage of some terms.
ZeroIntensityDec 14, 2024
48b145a
Play around with terminology.
ZeroIntensityDec 14, 2024
8ce3d7d
Various terminology changes.
ZeroIntensityDec 14, 2024
e5f1d18
Change the glossary definition a little bit.
ZeroIntensityDec 14, 2024
905ca5b
Change some phrasing.
ZeroIntensityDec 14, 2024
f2826c4
Fix some usage of terms.
ZeroIntensityDec 14, 2024
5c44391
Change some usage of 'global interpreter lock'
ZeroIntensityDec 15, 2024
7d5877f
Fix pre-commit lint.
ZeroIntensityDec 15, 2024
283fc92
Delete redundant file
ZeroIntensityDec 16, 2024
a7488ab
Revert "Delete redundant file"
ZeroIntensityDec 16, 2024
4c532b6
Remove accidental find-and-replace change.
ZeroIntensityDec 16, 2024
352acc5
Switch to a reference
ZeroIntensityDec 16, 2024
ed550bc
Use a less wordy phrase for detaching.
ZeroIntensityDec 16, 2024
d7cf403
Fix a typo in PyInterpreterState_Get
ZeroIntensityDec 16, 2024
f61a6da
Change some wording in PyEval_SaveThread and PyEval_RestoreThread
ZeroIntensityDec 16, 2024
36af941
Change wording for PyThreadState_Swap
ZeroIntensityDec 16, 2024
0b23daa
Make glossary terms more clear.
ZeroIntensityDec 16, 2024
163b0b8
Change up wording for 'attached thread state'
ZeroIntensityDec 16, 2024
3b2bed8
Clarify that the C API is what needs a thread state.
ZeroIntensityDec 16, 2024
80ae46b
Update Doc/glossary.rst
ZeroIntensityDec 17, 2024
3dee63f
Update Doc/glossary.rst
ZeroIntensityDec 17, 2024
9ed3a0b
Drop the phrase 'current thread state' and only use 'attached thread …
ZeroIntensityFeb 12, 2025
b3cbbf8
Add extra note about free-threading.
ZeroIntensityFeb 12, 2025
1c37d59
Add a seealso.
ZeroIntensityFeb 12, 2025
32a4937
Merge from main.
ZeroIntensityFeb 12, 2025
2fba67c
Fix weird merge artifact.
ZeroIntensityFeb 12, 2025
a0dc12c
Merge branch 'main' into clarify-gil-tstate
ZeroIntensityFeb 27, 2025
94619f6
Change term for new PyConfig* APIs
ZeroIntensityFeb 27, 2025
e6f1f28
Change term for PyUnstable_InterpreterState_GetMainModule
ZeroIntensityFeb 27, 2025
828d24b
Change term for Py_fopen
ZeroIntensityFeb 27, 2025
ace174f
Merge branch 'main' into clarify-gil-tstate
encukouMar 19, 2025
788d735
Change artifact from 'runtime context' to 'thread state'
ZeroIntensityMar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Document the term 'thread state.'
  • Loading branch information
@ZeroIntensity
ZeroIntensity committedDec 14, 2024
commitad7ee2d0c2f8d80ac5816b157c0af8ddf7bd935b
17 changes: 17 additions & 0 deletionsDoc/glossary.rst
View file
Open in desktop

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A few points to consider, which are reflected in my other comments:

  • current does not imply attached, but attached does implies current
  • the glossary probably isn't the best place for C-API details
  • "runtime context" or "execution context" might be a clearer term for users than "thread state"

The only tricky part is that we already talk about "contexts" relative to asyncio.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'll commit the suggestions tomorrow when I'm available to do a full find-and-replace so I don't blow up CI in the meantime.

For the per-thread thread state pointer (what a mouthful!), I'm happy with something like "runtime context," because there was no prior term for it, but I think we do want to keep the term "thread state." Thread states are documented, and users like to read the source code to understand some C functions--seeing_PyThreadState_GET and "thread state" in the documentation makes things more clear. That, and "context" doesn't convey the fact that it's a thread-local too well, which is important.

the glossary probably isn't the best place for C-API details

Hmm, we do have "borrowed reference" and "strong reference" in there; where else should "thread state" point to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"runtime context" or "execution context" might be a clearer term for users than "thread state"

I like "thread state" :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

+1 for sticking with thread state.

Between contextvars and context managers, and just the general idea of "context of execution", "context" is seriously overloaded already.

"thread state" isn't completely unambiguous (it could theoretically take on the holistic meaning of "all state associated with the current thread, including the execution stack and all thread local variables"), but the context(!) of use should help avoid that misinterpretation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"Runtime context" in particular is problematic, since the execution model is set up with the hierarchy of:

  • there is one runtime, which may be serially finalized and reinitialized, but you can never have more than one at a time
  • the runtime will host at least one interpreter, but may host more
  • each interpreter will have at least one thread state, but may have more
  • for an OS thread to execute Python code, it must be associated with a Python thread state (which also indirectly determines which interpreter it is associated with)

Original file line numberDiff line numberDiff line change
Expand Up@@ -622,6 +622,10 @@ Glossary
multi-threaded applications and makes it easier to use multi-core CPUs
efficiently. For more details, see :pep:`703`.

In Python's C API, a function might declare that it requires (or doesn't require)
the GIL to be held in order to use it. This refers to having an active
:term:`thread state` for the current thread.

hash-based pyc
A bytecode cache file that uses the hash rather than the last-modified
time of the corresponding source file to determine its validity. See
Expand DownExpand Up@@ -1281,6 +1285,19 @@ Glossary
See also :term:`binary file` for a file object able to read and write
:term:`bytes-like objects <bytes-like object>`.

thread state
In Python's C API, a thread state is a structure that holds
information about the current thread. A thread state must be
active for the current thread in order to call most of the C API.

On most builds of Python, an attached thread state means that the
caller holds the :term:`GIL` for the current interpreter, but on
:term:`free-threaded <free-threading>` builds, multiple thread states
can be active at once.

See :ref:`Thread State and the Global Interpreter Lock <threads>` for more
information.

triple-quoted string
A string which is bound by three instances of either a quotation mark
(") or an apostrophe ('). While they don't provide any functionality
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp