Fix some fallouts with Python free-threading enabled
cover Fix some fallouts with Python free-threading enabled
This is supplementary to the series entitled "Enable Python free-threading" sent to the openembedded-core mailing list.
Quoting parts of the cover letter from there:
===========================================================================
See https://docs.python.org/3/howto/free-threading-python.html
Quote:
Python support for free threading
Starting with the 3.13 release, CPython has support for a build of Python called free threading where the global interpreter lock (GIL) is disabled. Free-threaded execution allows for full utilization of the available processing power by running threads in parallel on available CPU cores. While not all software will benefit from this automatically, programs designed with threading in mind will run faster on multi-core hardware.
Some third-party packages, in particular ones with an extension module, may not be ready for use in a free-threaded build, and will re-enable the GIL.
...
Compatibility is poor for a lot of modules, that clearly spell this out in their pyproject.toml or PKG-INFO:
"Programming Language :: Python :: Free Threading :: 1 - Unstable"
or something not quite production level support.
It's still experimental for 3rd party modules, despite being officially supported for the interpreter and built-in modules in 3.14.
===========================================================================
That being said, a lot of python modules included in meta-openembedded do build and use the correct site-packages path after applying the two series, i.e. the module is installed into ${libdir}/python3.14t/site-packages
The usual warnings apply: DO NOT TRY THIS AT HOME. If it breaks, you need to keep both pieces.
RFC PATCH 1/6 ntpsec: Support Python free-threading
Use PYTHON_MAINVERSION instead of PYTHON_BASEVERSION because the former is suffixed with PYTHON_ABI for completeness.
This makes the python module to be installed into the correct location when Python free-threading is enabled.
--- meta-networking/recipes-support/ntpsec/ntpsec_1.2.4.bb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta-networking/recipes-support/ntpsec/ntpsec_1.2.4.bb +2 -2
@@ -50,8 +50,8 @@ CC[unexport] = "1" CFLAGS[unexport] = "1" LDFLAGS[unexport] = "1" -export PYTHON_VERSION = "${PYTHON_BASEVERSION}" -export PYTAG = "cpython${@ d.getVar('PYTHON_BASEVERSION').replace('.', '')}" +export PYTHON_VERSION = "${PYTHON_MAINVERSION}" +export PYTAG = "cpython${@ d.getVar('PYTHON_MAINVERSION').replace('.', '')}" export pyext_PATTERN = "%s.so" export PYTHON_LDFLAGS = "-lpthread -ldl"
Signature · 1 line
2.53.0
RFC PATCH 2/6 libuser: Support Python free-threading
In reply to Zoltán Böszörményilibuser installs its python module into the ABI-less site-packages directory.
Move the installed site-packages directory to the correct location if needed.
--- meta-gnome/recipes-support/libuser/libuser_0.64.bb | 6 ++++++ 1 file changed, 6 insertions(+)
meta-gnome/recipes-support/libuser/libuser_0.64.bb +6 -0
@@ -36,6 +36,12 @@ do_configure:prepend() { cd - } +do_install:append () { + if [ ! -d ${D}${libdir}/${PYTHON_DIR} ]; then + mv ${D}${libdir}/python${PYTHON_BASEVERSION} ${D}${libdir}/${PYTHON_DIR} + fi +} + PACKAGES += "${PN}-python " FILES:${PN}-python = "${PYTHON_SITEPACKAGES_DIR}"
Signature · 1 line
2.53.0
RFC PATCH 3/6 libpwquality: Support Python free-threading
In reply to Zoltán BöszörményiUse PYTHON_MAINVERSION instead of PYTHON_BASEVERSION. The former now contains PYTHON_ABI. This makes the python module to be installed into the correct location.
--- meta-oe/recipes-extended/libpwquality/libpwquality_1.4.5.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta-oe/recipes-extended/libpwquality/libpwquality_1.4.5.bb +1 -1
@@ -24,7 +24,7 @@ export PYTHON_DIR export BUILD_SYS export HOST_SYS -EXTRA_OECONF += "--with-python-rev=${PYTHON_BASEVERSION} \ +EXTRA_OECONF += "--with-python-rev=${PYTHON_MAINVERSION} \ --with-python-binary=${STAGING_BINDIR_NATIVE}/python3-native/python3 \ --with-pythonsitedir=${PYTHON_SITEPACKAGES_DIR} \ --libdir=${libdir} \
Signature · 1 line
2.53.0
RFC PATCH 4/6 upm: Support Python free-threading
In reply to Zoltán BöszörményiAdd -DPYTHON3_PACKAGES_PATH=${PYTHON_SITEPACKAGES_DIR} to the compilation options to make sure the python module is installed into the correct location.
--- meta-oe/recipes-extended/upm/upm_git.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta-oe/recipes-extended/upm/upm_git.bb +1 -1
@@ -45,7 +45,7 @@ BINDINGS:armv5 ??= "python" PACKAGECONFIG ??= "${@bb.utils.contains('PACKAGES', 'node-${PN}', 'nodejs', '', d)} \ ${@bb.utils.contains('PACKAGES', 'python3-${PN}', 'python', '', d)}" -PACKAGECONFIG[python] = "-DBUILDSWIGPYTHON=ON -DPYTHON_LIBRARY=${STAGING_LIBDIR}/lib${PYTHON_DIR}.so -DPYTHON_INCLUDE_DIR=${STAGING_INCDIR}/${PYTHON_DIR}, -DBUILDSWIGPYTHON=OFF, swig-native python3," +PACKAGECONFIG[python] = "-DBUILDSWIGPYTHON=ON -DPYTHON3_PACKAGES_PATH=${PYTHON_SITEPACKAGES_DIR} -DPYTHON_LIBRARY=${STAGING_LIBDIR}/lib${PYTHON_DIR}.so -DPYTHON_INCLUDE_DIR=${STAGING_INCDIR}/${PYTHON_DIR}, -DBUILDSWIGPYTHON=OFF, swig-native python3," PACKAGECONFIG[nodejs] = "-DBUILDSWIGNODE=ON, -DBUILDSWIGNODE=OFF, swig-native nodejs-native," do_configure:prepend() {
Signature · 1 line
2.53.0
RFC PATCH 5/6 fontforge: Allow different PYTHON_ABI set for native and target
In reply to Zoltán BöszörményiThe enablement setting for Python free-threading may be different for native and target builds.
Use PYTHON_DIR_NATIVE for BUILD_LDFLAGS to use the native build.
--- meta-oe/recipes-graphics/fontforge/fontforge_20251009.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta-oe/recipes-graphics/fontforge/fontforge_20251009.bb +1 -1
@@ -35,7 +35,7 @@ PACKAGECONFIG[readline] = "-DENABLE_READLINE=ON,-DENABLE_READLINE=OFF,readline" CFLAGS += "-fno-strict-aliasing" LDFLAGS += "-l${PYTHON_DIR}" -BUILD_LDFLAGS += "-l${PYTHON_DIR}" +BUILD_LDFLAGS += "-l${PYTHON_DIR_NATIVE}" PACKAGES =+ "${PN}-python"
Signature · 1 line
2.53.0
RFC PATCH 6/6 opencv: Support Python free-threading
In reply to Zoltán Böszörményiopencv installs its python module into the ABI-less site-packages directory.
Move the installed site-packages directory to the correct location if needed.
--- meta-oe/recipes-support/opencv/opencv_4.13.0.bb | 4 ++++ 1 file changed, 4 insertions(+)
meta-oe/recipes-support/opencv/opencv_4.13.0.bb +4 -0
@@ -224,6 +224,10 @@ do_install:append() { # mesa-demos /usr/bin/shape file. mv ${D}/${bindir}/shape ${D}/${bindir}/opencv_shape fi + + if [ ! -d ${D}${libdir}/${PYTHON_DIR} ]; then + mv ${D}${libdir}/python${PYTHON_BASEVERSION} ${D}${libdir}/${PYTHON_DIR} + fi } do_install:append:class-target() {
Signature · 1 line
2.53.0