8000 [3.14] gh-135645: Added `supports_isolated_interpreters` to `sys.impl… · python/cpython@fa62dfe · GitHub
[go: up one dir, main page]

Skip to content

Commit fa62dfe

Browse files
miss-islingtonsobolevnericsnowcurrently
authored
[3.14] gh-135645: Added supports_isolated_interpreters to sys.implementation (GH-135667) (#135786)
gh-135645: Added `supports_isolated_interpreters` to `sys.implementation` (GH-135667) (cherry picked from commit 8ca1e4d) Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
1 parent b1d5e23 commit fa62dfe

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Doc/library/sys.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
11851185
``cache_tag`` is set to ``None``, it indicates that module caching should
11861186
be disabled.
11871187

1188+
*supports_isolated_interpreters* is a boolean value, whether
1189+
this implementation supports multiple isolated interpreters.
1190+
It is ``True`` for CPython on most platforms. Platforms with
1191+
this support implement the low-level :mod:`!_interpreters` module.
1192+
1193+
.. seealso::
1194+
1195+
:pep:`684`, :pep:`734`, and :mod:`concurrent.interpreters`.
1196+
11881197
:data:`sys.implementation` may contain additional attributes specific to
11891198
the Python implementation. These non-standard attributes must start with
11901199
an underscore, and are not described here. Regardless of its contents,
@@ -1194,6 +1203,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only
11941203

11951204
.. versionadded:: 3.3
11961205

1206+
.. versionchanged:: 3.14
1207+
Added ``supports_isolated_interpreters`` field.
1208+
11971209
.. note::
11981210

11991211
The addition of new required attributes must go through the normal PEP

Lib/test/test_sys.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ def test_implementation(self):
10741074
self.assertHasAttr(sys.implementation, 'version')
10751075
self.assertHasAttr(sys.implementation, 'hexversion')
10761076
self.assertHasAttr(sys.implementation, 'cache_tag')
1077+
self.assertHasAttr(sys.implementation, 'supports_isolated_interpreters')
10771078

10781079
version = sys.implementation.version
10791080
self.assertEqual(version[:2], (version.major, version.minor))
@@ -1087,6 +1088,15 @@ def test_implementation(self):
10871088
self.assertEqual(sys.implementation.name,
10881089
sys.implementation.name.lower())
10891090

1091+
# https://peps.python.org/pep-0734
1092+
sii = sys.implementation.supports_isolated_interpreters
1093+
self.assertIsInstance(sii, bool)
1094+
if test.support.check_impl_detail(cpython=True):
1095+
if test.support.is_emscripten or test.support.is_wasi:
1096+
self.assertFalse(sii)
1097+
else:
1098+
self.assertTrue(sii)
1099+
10901100
@test.support.cpython_only
10911101
def test_debugmallocstats(self):
10921102
# Test sys._debugmallocstats()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added ``supports_isolated_interpreters`` field to
2+
:data:`sys.implementation`.

Python/sysmodule.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,18 @@ make_impl_info(PyObject *version_info)
36063606
goto error;
36073607
#endif
36083608

3609+
// PEP-734
3610+
#if defined(__wasi__) || defined(__EMSCRIPTEN__)
3611+
// It is not enabled on WASM builds just yet
3612+
value = Py_False;
3613+
#else
3614+
value = Py_True;
3615+
#endif
3616+
res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", value);
3617+
if (res < 0) {
3618+
goto error;
3619+
}
3620+
36093621
/* dict ready */
36103622

36113623
ns = _PyNamespace_New(impl_info);

0 commit comments

Comments
 (0)
0