Skip to content

[subinterpreters] Improve Interpreter Isolation for Uses of PyArg_Parser #95909

Closed
@ericsnowcurrently

Description

@ericsnowcurrently

(This is a follow-up to gh-90928.)

Argument clinic adds a static local PyArg_Parser for each function it generates. Each of those variables is initialized at runtime the first time it is used (even though, technically, it could be done statically). That means there's a (very unlikely) race on initializing each of those variables, at least once interpreters stop sharing the GIL. Furthermore, the PyArg_Parser.kwtuple field holds a PyObject *, which means we're leaking objects between interpreters (albeit completely immutable ones), and there still can be a race on refcounts if we don't do something about it. (For core cases, incl. builtin modules, we statically initialize kwtuple, but not for extension modules.)

For the sake of isolation (and of a per-interpreter GIL) we should store PyArg_Parser.kwtuple on PyInterpreterState in the cases where we aren't statically initializing it. For per-interpreter GIL we should also add a global lock around initializing each static PyArg_Parser.

Metadata

Metadata

Labels

type-featureA feature request or enhancement

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions