Skip to content

gh-107784 Document interpid C-API and new Unstable API for fetching __main__ of interpreter #112548

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm giving this some attention so that we can get it merged soon.
This section looks good so far

----------------------

A interpreter ID identifies a interpreter and may be used as an int.
Copy link
Contributor

Choose a reason for hiding this comment

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

@hugovk suggested that you link to the class definition,
changing

A interpreter ID identifies a interpreter and may be used as an int.

to

A interpreter ID identifies a interpreter and may be used as an :class:`int`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A interpreter ID identifies a interpreter and may be used as an int.
A interpreter ID identifies a interpreter and may be used as an :class:`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
---------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added documentation for the ``PyUnstable_InterpreterState_GetMainModule``
and ``PyInterpreterID`` C-API. Patch by Anthony Shaw.