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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

See also :c:func:`PyEval_GetFrame`.

*tstate* must not be ``NULL``.
*tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>`.

.. versionadded:: 3.9


.. c:function:: uint64_t PyThreadState_GetID(PyThreadState *tstate)

Get the unique thread state identifier of the Python thread state *tstate*.
Get the unique :term:`thread state` identifier of the Python thread state *tstate*.

*tstate* must not be ``NULL``.
*tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>`.

.. versionadded:: 3.9

Expand All @@ -1451,7 +1451,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

Get the interpreter of the Python thread state *tstate*.

*tstate* must not be ``NULL``.
*tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>`.

.. versionadded:: 3.9

Expand Down Expand Up @@ -1480,11 +1480,9 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

Get the current interpreter.

Issue a fatal error if there no current Python thread state or no current
Issue a fatal error if there no :term:`attached thread state` or no current
interpreter. It cannot return NULL.

The caller must have an :term:`attached thread state`.

.. versionadded:: 3.9


Expand Down Expand Up @@ -1543,9 +1541,10 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

Return a dictionary in which extensions can store thread-specific state
information. Each extension should use a unique key to use to store state in
the dictionary. It is okay to call this function when no current thread state
is available. If this function returns ``NULL``, no exception has been raised and
the caller should assume no current thread state is available.
the dictionary. It is okay to call this function when no :term:`thread state`
is :term:`attached <attached thread state>`. If this function returns
``NULL``, no exception has been raised and the caller should assume no
thread state is attached.


.. c:function:: int PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
Expand All @@ -1564,9 +1563,8 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate)

Acquire the global interpreter lock and set the current thread state to
*tstate*, which must not be ``NULL``. The lock must have been created earlier.
If this thread already has the lock, deadlock ensues.
Set the :term:`current thread state` to *tstate*, which must not be ``NULL`` or
:term:`attached <attached thread state>`.

.. note::
Calling this function from a thread when the runtime is finalizing will
Expand All @@ -1589,10 +1587,9 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

.. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate)

Reset the current thread state to ``NULL`` and release the global interpreter
lock. The lock must have been created earlier and must be held by the current
thread. The *tstate* argument, which must not be ``NULL``, is only used to check
that it represents the current thread state --- if it isn't, a fatal error is
Reset the :term:`current thread state` to ``NULL``.
The *tstate* argument, which must not be ``NULL``, is only used to check
that it represents the :term:`attached thread state` --- if it isn't, a fatal error is
reported.

:c:func:`PyEval_SaveThread` is a higher-level function which is always
Expand Down Expand Up @@ -1732,20 +1729,19 @@ function. You can create and destroy them using the following functions:
The given *config* controls the options with which the interpreter
is initialized.

Upon success, *tstate_p* will be set to the first thread state
created in the new
sub-interpreter. This thread state is made in the current thread state.
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
current thread state and there may not be a current thread state.
:term:`attached thread state`, which might not exist.

Like all other Python/C API functions, the global interpreter lock
must be held before calling this function and is still held when it
returns. Likewise a current thread state must be set on entry. On
success, the returned thread state will be set as current. If the
sub-interpreter is created with its own :term:`GIL` then the
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
Expand Down Expand Up @@ -1831,14 +1827,10 @@ function. You can create and destroy them using the following functions:

.. index:: single: Py_FinalizeEx (C function)

Destroy the (sub-)interpreter represented by the given thread state.
The given thread state must be the current thread state. See the
discussion of thread states below. When the call returns,
the current thread state is ``NULL``. All thread states associated
with this interpreter are destroyed. The global interpreter lock
used by the target interpreter must be held before calling this
function. No :term:`thread state` is :term:`attached <attached thread state>`
when it returns.
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, the :term:`current thread state` is ``NULL``.
All thread states associated with this interpreter are destroyed.

:c:func:`Py_FinalizeEx` will destroy all sub-interpreters that
haven't been explicitly destroyed at that point.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.