Skip to content

gh-135645: Added supports_isolated_interpreters to sys.implementation #135667

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

Merged
merged 9 commits into from
Jun 21, 2025
Merged
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
12 changes: 12 additions & 0 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
``cache_tag`` is set to ``None``, it indicates that module caching should
be disabled.

*supports_isolated_interpreters* is a boolean value, whether
this implementation supports multiple isolated interpreters.
It is ``True`` for CPython on most platforms. Platforms with
this support implement the low-level :mod:`!_interpreters` module.

.. seealso::

:pep:`684`, :pep:`734`, and :mod:`concurrent.interpreters`.

:data:`sys.implementation` may contain additional attributes specific to
the Python implementation. These non-standard attributes must start with
an underscore, and are not described here. Regardless of its contents,
Expand All @@ -1194,6 +1203,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only

.. versionadded:: 3.3

.. versionchanged:: 3.14
Added ``supports_isolated_interpreters`` field.

.. note::

The addition of new required attributes must go through the normal PEP
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ def test_implementation(self):
self.assertHasAttr(sys.implementation, 'version')
self.assertHasAttr(sys.implementation, 'hexversion')
self.assertHasAttr(sys.implementation, 'cache_tag')
self.assertHasAttr(sys.implementation, 'supports_isolated_interpreters')

version = sys.implementation.version
self.assertEqual(version[:2], (version.major, version.minor))
Expand All @@ -1087,6 +1088,15 @@ def test_implementation(self):
self.assertEqual(sys.implementation.name,
sys.implementation.name.lower())

# https://peps.python.org/pep-0734
sii = sys.implementation.supports_isolated_interpreters
self.assertIsInstance(sii, bool)
if test.support.check_impl_detail(cpython=True):
if test.support.is_emscripten or test.support.is_wasi:
self.assertFalse(sii)
else:
self.assertTrue(sii)

@test.support.cpython_only
def test_debugmallocstats(self):
# Test sys._debugmallocstats()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added ``supports_isolated_interpreters`` field to
:data:`sys.implementation`.
12 changes: 12 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,18 @@ make_impl_info(PyObject *version_info)
goto error;
#endif

// PEP-734
#if defined(__wasi__) || defined(__EMSCRIPTEN__)
// It is not enabled on WASM builds just yet
value = Py_False;
#else
value = Py_True;
#endif
res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", value);
if (res < 0) {
goto error;
}

/* dict ready */

ns = _PyNamespace_New(impl_info);
Expand Down
Loading