[Python-Dev] Making PyInterpreterState an opaque type

Eric Snow ericsnowcurrently at gmail.com
Fri Feb 15 18:37:53 EST 2019


Hi all,

I've been working on the runtime lately, particularly focused on my
multi-core Python project.  One thing that would help simplify changes
in this area is if PyInterpreterState were defined in
Include/internal.  This would mean the type would be opaque unless
Py_BUILD_CORE were defined.

The docs [1] already say none of the struct's fields are public.
Furthermore, Victor already moved it into Include/cpython (i.e. not in
the stable ABI) in November.  Overall, the benefit of making internal
types like this opaque is realized in our ability to change the
internal details without further breaking C-API users.

Realistically, there may be extension modules out there that use
PyInterpreterState fields directly.  They would break.  I expect there
to be few such modules and fixing them would not involve great effort.
We'd have to add any missing accessor functions to the public C-API,
which I see as a good thing.  I have an issue [2] open for the change
and a PR open.  My PR already adds an entry to the porting section of
the 3.8 What's New doc about dealing with PyInterpreterState.

Anyway, I just wanted to see if there are any objections to making
PyInterpreterState an opaque type outside of core use.

-eric

p.s. I'd like to do the same with PyThreadState, but that's a bit
trickier [3] and not one of my immediate needs. :)


[1] https://docs.python.org/3/c-api/init.html#c.PyInterpreterState
[2] https://bugs.python.org/issue35886
[3] https://bugs.python.org/issue35949


More information about the Python-Dev mailing list