.. versionadded:: 3.9
+.. c:function:: uint64_t PyThreadState_GetID(PyThreadState *tstate)
+
+ Get the unique thread state identifier of the Python thread state *tstate*.
+
+ *tstate* must not be ``NULL``.
+
+ .. versionadded:: 3.9
+
+
.. c:function:: PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
Get the interpreter of the Python thread state *tstate*.
:c:func:`PyInterpreterState_Get` functions to get the interpreter.
New :c:func:`PyThreadState_GetFrame` function to get the current frame of a
Python thread state.
+ New :c:func:`PyThreadState_GetID` function: get the unique identifier of a
+ Python thread state.
(Contributed by Victor Stinner in :issue:`39947`.)
* Add ``--with-platlibdir`` option to the ``configure`` script: name of the
/* New in 3.9 */
PyAPI_FUNC(PyInterpreterState*) PyThreadState_GetInterpreter(PyThreadState *tstate);
PyAPI_FUNC(struct _frame*) PyThreadState_GetFrame(PyThreadState *tstate);
+PyAPI_FUNC(uint64_t) PyThreadState_GetID(PyThreadState *tstate);
#endif
typedef
--- /dev/null
+Add :c:func:`PyThreadState_GetID` function: get the unique identifier of a
+Python thread state.
PyObject *rl;
PyThreadState *ts = PyThreadState_Get();
- if (ts->id == cached_running_holder_tsid && cached_running_holder != NULL) {
+ uint64_t ts_id = PyThreadState_GetID(ts);
+ if (ts_id == cached_running_holder_tsid && cached_running_holder != NULL) {
// Fast path, check the cache.
rl = cached_running_holder; // borrowed
}
}
cached_running_holder = rl; // borrowed
- cached_running_holder_tsid = ts->id;
+ cached_running_holder_tsid = ts_id;
}
assert(Py_IS_TYPE(rl, &PyRunningLoopHolder_Type));
}
+uint64_t
+PyThreadState_GetID(PyThreadState *tstate)
+{
+ assert(tstate != NULL);
+ return tstate->id;
+}
+
+
/* Asynchronously raise an exception in a thread.
Requested by Just van Rossum and Alex Martelli.
To prevent naive misuse, you must write your own extension