From 47d2b0b5b1a9576405e19b2d5a41daea2ddae017 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 7 Oct 2026 16:24:09 -0700 Subject: [PATCH 1/4] gh-158996: Check that Emscripten free-threaded build works --- Platforms/emscripten/__main__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Platforms/emscripten/__main__.py b/Platforms/emscripten/__main__.py index 84a1589b81f6a20..44f110870dc6e99 100644 --- a/Platforms/emscripten/__main__.py +++ b/Platforms/emscripten/__main__.py @@ -505,6 +505,8 @@ def configure_emscripten_python(context, working_dir): f"--with-build-python={build_python}", "--without-pymalloc", "--disable-shared", + "--disable-gil", + "--with-mimalloc", "--disable-ipv6", "--enable-big-digits=30", "--enable-wasm-dynamic-linking", From a967b3572cabf24e207f10b4218925a83bcc1fd1 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 8 Oct 2026 09:48:01 -0700 Subject: [PATCH 2/4] Make EmscriptenInfoType into a managed static builtin --- Python/sysmodule.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index afc90d9bf5d7dd6..615c14aea0a1404 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3844,7 +3844,7 @@ PyDoc_STRVAR(emscripten_info__doc__, \n\ WebAssembly Emscripten platform information."); -static PyTypeObject *EmscriptenInfoType; +static PyTypeObject EmscriptenInfoType; static PyStructSequence_Field emscripten_info_fields[] = { {"emscripten_version", "Emscripten version (major, minor, micro)"}, @@ -3908,7 +3908,7 @@ make_emscripten_info(void) char *ua; int pos = 0; - emscripten_info = PyStructSequence_New(EmscriptenInfoType); + emscripten_info = PyStructSequence_New(&EmscriptenInfoType); if (emscripten_info == NULL) { return NULL; } @@ -4071,6 +4071,11 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict) SET_SYS_FROM_STRING("_vpath", VPATH); #endif +#ifdef __EMSCRIPTEN__ + ENSURE_INFO_TYPE(EmscriptenInfoType, emscripten_info_desc); + SET_SYS("_emscripten_info", make_emscripten_info()); +#endif + #undef ENSURE_INFO_TYPE /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */ @@ -4091,16 +4096,6 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict) goto type_init_failed; } -#ifdef __EMSCRIPTEN__ - if (EmscriptenInfoType == NULL) { - EmscriptenInfoType = PyStructSequence_NewType(&emscripten_info_desc); - if (EmscriptenInfoType == NULL) { - goto type_init_failed; - } - } - SET_SYS("_emscripten_info", make_emscripten_info()); -#endif - /* adding sys.path_hooks and sys.path_importer_cache */ SET_SYS("meta_path", PyList_New(0)); SET_SYS("path_importer_cache", PyDict_New()); @@ -4408,9 +4403,7 @@ _PySys_FiniTypes(PyInterpreterState *interp) _PyStructSequence_FiniBuiltin(interp, &Hash_InfoType); _PyStructSequence_FiniBuiltin(interp, &AsyncGenHooksType); #ifdef __EMSCRIPTEN__ - if (_Py_IsMainInterpreter(interp)) { - Py_CLEAR(EmscriptenInfoType); - } + _PyStructSequence_FiniBuiltin(interp, &EmscriptenInfoType); #endif } From 406aa14857b59ef462fe4568e85e1e9cbbb5bd82 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 8 Oct 2026 09:52:01 -0700 Subject: [PATCH 3/4] Add requires_working_threading() to TestPyThreadId --- Lib/test/test_capi/test_misc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 9a5a1d938e2869f..fe6a551b3d33993 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -2964,6 +2964,7 @@ def func(): @unittest.skipUnless(support.Py_GIL_DISABLED, 'need Py_GIL_DISABLED') +@threading_helper.requires_working_threading() class TestPyThreadId(unittest.TestCase): def test_py_thread_id(self): # gh-112535: Test _Py_ThreadId(): make sure that thread identifiers From f7d4adef2875dcf295bf94a580c5e729aa63741f Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 8 Oct 2026 12:04:28 -0700 Subject: [PATCH 4/4] Add some more requires guards to tests --- Lib/test/test_warnings/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 5b5d5c2f70ffd7a..b0e367913faa1af 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -15,6 +15,7 @@ from test.support import import_helper from test.support import isolation from test.support import os_helper +from test.support import threading_helper from test.support import warnings_helper from test.support import force_not_colorized from test.support.script_helper import assert_python_ok, assert_python_failure @@ -1806,6 +1807,7 @@ def test_late_resource_warning(self): self.assertStartsWith(err, expected) +@support.requires_working_socket() class AsyncTests(BaseTest): """Verifies that the catch_warnings() context manager behaves as expected when used inside async co-routines. This requires @@ -1900,6 +1902,7 @@ class PyAsyncTests(AsyncTests, unittest.TestCase): module = py_warnings +@threading_helper.requires_working_threading() class ThreadTests(BaseTest): """Verifies that the catch_warnings() context manager behaves as expected when used within threads. This requires that both the