diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index e89641f74c7491..140ea7af0c624b 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -1225,6 +1225,12 @@ All of the following functions must be called after :c:func:`Py_Initialize`. :c:func:`PyEval_SaveThread` is a higher-level function which is always available (even when threads have not been initialized). +.. c:function:: PyObject* PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *interp) + + Returns a :term:`strong reference` to the ``__main__`` module of the given interpreter *interp*. + Fails with a :exc:`RuntimeError` if the interpreter is not initialized. + + .. versionadded:: 3.12 .. _sub-interpreter-support: @@ -1464,6 +1470,29 @@ function. You can create and destroy them using the following functions: :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that haven't been explicitly destroyed at that point. +Interpreter ID Objects +---------------------- + +A interpreter ID identifies a interpreter and may be used as an int. + +.. versionadded:: 3.12 + +.. c:var:: PyTypeObject PyInterpreterID_Type + + This instance of :c:type:`PyTypeObject` represents the Python interpreter ID type. + +.. c:function:: PyObject* PyInterpreterID_New(int64_t id) + + Returns a new interpreter ID object with the given *id*. + +.. c:function:: PyInterpreterState* PyInterpreterID_LookUp(PyObject *requested_id) + + Returns a :term:`borrowed reference` to the :c:type:`PyInterpreterState` interpreter state for the given interpreter ID object *requested_id*. + Fails with :exc:`RuntimeError` if the interpreter is not found. + +.. c:function:: PyObject* PyInterpreterState_GetIDObject(PyInterpreterState *interp) + + Returns a new interpreter ID object for the given interpreter state *interp*. A Per-Interpreter GIL --------------------- diff --git a/Misc/NEWS.d/next/Documentation/2023-11-30-18-44-35.gh-issue-107784.5okblM.rst b/Misc/NEWS.d/next/Documentation/2023-11-30-18-44-35.gh-issue-107784.5okblM.rst new file mode 100644 index 00000000000000..3cfaddfceb8c22 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2023-11-30-18-44-35.gh-issue-107784.5okblM.rst @@ -0,0 +1,2 @@ +Added documentation for the ``PyUnstable_InterpreterState_GetMainModule`` +and ``PyInterpreterID`` C-API. Patch by Anthony Shaw.