@@ -1433,16 +1433,16 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14331433
14341434 See also :c:func:`PyEval_GetFrame`.
14351435
1436- *tstate* must not be ``NULL``.
1436+ *tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>` .
14371437
14381438 .. versionadded:: 3.9
14391439
14401440
14411441.. c:function:: uint64_t PyThreadState_GetID(PyThreadState *tstate)
14421442
1443- Get the unique thread state identifier of the Python thread state *tstate*.
1443+ Get the unique :term:` thread state` identifier of the Python thread state *tstate*.
14441444
1445- *tstate* must not be ``NULL``.
1445+ *tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>` .
14461446
14471447 .. versionadded:: 3.9
14481448
@@ -1451,7 +1451,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14511451
14521452 Get the interpreter of the Python thread state *tstate*.
14531453
1454- *tstate* must not be ``NULL``.
1454+ *tstate* must not be ``NULL``, and must be :term:`attached <attached thread state>` .
14551455
14561456 .. versionadded:: 3.9
14571457
@@ -1480,11 +1480,9 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14801480
14811481 Get the current interpreter.
14821482
1483- Issue a fatal error if there no current Python thread state or no current
1483+ Issue a fatal error if there no :term:`attached thread state` or no current
14841484 interpreter. It cannot return NULL.
14851485
1486- The caller must have an :term:`attached thread state`.
1487-
14881486 .. versionadded:: 3.9
14891487
14901488
@@ -1543,9 +1541,10 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15431541
15441542 Return a dictionary in which extensions can store thread-specific state
15451543 information. Each extension should use a unique key to use to store state in
1546- the dictionary. It is okay to call this function when no current thread state
1547- is available. If this function returns ``NULL``, no exception has been raised and
1548- the caller should assume no current thread state is available.
1544+ the dictionary. It is okay to call this function when no :term:`thread state`
1545+ is :term:`attached <attached thread state>`. If this function returns
1546+ ``NULL``, no exception has been raised and the caller should assume no
1547+ thread state is attached.
15491548
15501549
15511550.. c:function:: int PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
@@ -1564,9 +1563,8 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15641563
15651564.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate)
15661565
1567- Acquire the global interpreter lock and set the current thread state to
1568- *tstate*, which must not be ``NULL``. The lock must have been created earlier.
1569- If this thread already has the lock, deadlock ensues.
1566+ Set the :term:`current thread state` to *tstate*, which must not be ``NULL`` or
1567+ :term:`attached <attached thread state>`.
15701568
15711569 .. note::
15721570 Calling this function from a thread when the runtime is finalizing will
@@ -1589,10 +1587,9 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15891587
15901588.. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate)
15911589
1592- Reset the current thread state to ``NULL`` and release the global interpreter
1593- lock. The lock must have been created earlier and must be held by the current
1594- thread. The *tstate* argument, which must not be ``NULL``, is only used to check
1595- that it represents the current thread state --- if it isn't, a fatal error is
1590+ Reset the :term:`current thread state` to ``NULL``.
1591+ The *tstate* argument, which must not be ``NULL``, is only used to check
1592+ that it represents the :term:`attached thread state` --- if it isn't, a fatal error is
15961593 reported.
15971594
15981595 :c:func:`PyEval_SaveThread` is a higher-level function which is always
@@ -1732,20 +1729,19 @@ function. You can create and destroy them using the following functions:
17321729 The given *config* controls the options with which the interpreter
17331730 is initialized.
17341731
1735- Upon success, *tstate_p* will be set to the first thread state
1736- created in the new
1737- sub-interpreter. This thread state is made in the current thread state .
1732+ Upon success, *tstate_p* will be set to the first :term:` thread state`
1733+ created in the new sub-interpreter. This thread state is
1734+ :term:`attached <attached thread state>` .
17381735 Note that no actual thread is created; see the discussion of thread states
17391736 below. If creation of the new interpreter is unsuccessful,
17401737 *tstate_p* is set to ``NULL``;
17411738 no exception is set since the exception state is stored in the
1742- current thread state and there may not be a current thread state .
1739+ :term:`attached thread state`, which might not exist .
17431740
1744- Like all other Python/C API functions, the global interpreter lock
1745- must be held before calling this function and is still held when it
1746- returns. Likewise a current thread state must be set on entry. On
1747- success, the returned thread state will be set as current. If the
1748- sub-interpreter is created with its own :term:`GIL` then the
1741+ Like all other Python/C API functions, an :term:`attached thread state`
1742+ must be present before calling this function, but it might be detached upon
1743+ returning. On success, the returned thread state will be :term:`attached <attached thread state>`.
1744+ If the sub-interpreter is created with its own :term:`GIL` then the
17491745 :term:`attached thread state` of the calling interpreter will be detached.
17501746 When the function returns, the new interpreter's :term:`thread state`
17511747 will be :term:`attached <attached thread state>` to the current thread and
@@ -1831,14 +1827,10 @@ function. You can create and destroy them using the following functions:
18311827
18321828 .. index:: single: Py_FinalizeEx (C function)
18331829
1834- Destroy the (sub-)interpreter represented by the given thread state.
1835- The given thread state must be the current thread state. See the
1836- discussion of thread states below. When the call returns,
1837- the current thread state is ``NULL``. All thread states associated
1838- with this interpreter are destroyed. The global interpreter lock
1839- used by the target interpreter must be held before calling this
1840- function. No :term:`thread state` is :term:`attached <attached thread state>`
1841- when it returns.
1830+ Destroy the (sub-)interpreter represented by the given :term:`thread state`.
1831+ The given thread state must be :term:`attached <attached thread state>`.
1832+ When the call returns, the :term:`current thread state` is ``NULL``.
1833+ All thread states associated with this interpreter are destroyed.
18421834
18431835 :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that
18441836 haven't been explicitly destroyed at that point.
0 commit comments