Improve Py_mod_multiple_interpreters and Py_mod_gil Usability #132861
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-C-API
topic-free-threading
topic-subinterpreters
type-feature
A feature request or enhancement
Feature or enhancement
Proposal:
Here are some deficiencies:
Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED
andPy_MOD_PER_INTERPRETER_GIL_SUPPORTED
is unclearPy_MOD_PER_INTERPRETER_GIL_SUPPORTED
applies to the vast majority of extensions and should be the defaultPy_mod_gil
doesn't have an option that explicitly covers the case where an external dependency is not thread-safePy_MOD_MULTIPLE_INTERPRETERS_SUPPORTED
implies an external dependency is not thread-safe and/or isolated to each interpreter; it should be the other way around (and be a synonym forPy_MOD_PER_INTERPRETER_GIL_SUPPORTED
), which would introduce a need for aPy_MOD_PER_INTERPRETER_GIL_NOT_SUPPORTED
We could take a simple approach, working with the existing slots:
Py_MOD_PER_INTERPRETER_GIL_NOT_SUPPORTED
Py_MOD_GIL_USED_FOR_EXTERNAL
I think we could do better, by replacing the existing slots with new ones that focus explicitly on what we care about:
Py_mod_isolation
Py_MOD_NOT_ISOLATED
- the module has process-global state and/or objects (e.g. static types)Py_MOD_ISOLATED
(default) - the module's state/objects have been isolated to the module (i.e interpreter)Py_mod_threadsafe
Py_MOD_NOT_THREADSAFE
(default) - the module's own state/code is not thread-safePy_MOD_THREADSAFE
- the module's state/code are thread-safe; external dependencies are covered byPy_mod_external_libs
Py_mod_external_libs
Py_MOD_EXTERN_NOT_THREADSAFE
- at least one external dependency is not thread-safe (may be used without the GIL held)Py_MOD_EXTERN_NOT_ISOLATED
- at least one external dependency is not isolated to the module object (i.e. interpreter)Py_MOD_EXTERN_ISOLATED
(default) - all external dependencies are isolated and using them is thread-safePy_mod_isolation
andPy_mod_threadsafe
, external dependencies are covered byPy_mod_external_libs
Py_mod_multiple_interpreters
slotPy_mod_gil
slotRegarding the defaults, for
Py_mod_isolation
, multi-phase init implies isolation (per PEP 489). ForPy_mod_external_libs
, we assume that the vast majority of modules will not have problematic dependencies.Equivalents to current usage:
CC @encukou
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: