From 9fa551f599c8097cddd6c3d825b8e4bdcdda32d3 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 22 May 2025 13:46:11 -0700 Subject: [PATCH] DNM: disable the GIL (experimental) in 3.13+ --- 3.13/alpine3.21/Dockerfile | 21 +++++++++++++++++++++ 3.13/alpine3.22/Dockerfile | 21 +++++++++++++++++++++ 3.13/bookworm/Dockerfile | 21 +++++++++++++++++++++ 3.13/slim-bookworm/Dockerfile | 21 +++++++++++++++++++++ 3.13/slim-trixie/Dockerfile | 21 +++++++++++++++++++++ 3.13/trixie/Dockerfile | 21 +++++++++++++++++++++ 3.14/alpine3.21/Dockerfile | 21 +++++++++++++++++++++ 3.14/alpine3.22/Dockerfile | 21 +++++++++++++++++++++ 3.14/bookworm/Dockerfile | 21 +++++++++++++++++++++ 3.14/slim-bookworm/Dockerfile | 21 +++++++++++++++++++++ 3.14/slim-trixie/Dockerfile | 21 +++++++++++++++++++++ 3.14/trixie/Dockerfile | 21 +++++++++++++++++++++ Dockerfile-linux.template | 34 ++++++++++++++++++++++++++++++++++ 13 files changed, 286 insertions(+) diff --git a/3.13/alpine3.21/Dockerfile b/3.13/alpine3.21/Dockerfile index 676dd7adf..c7fe210d1 100644 --- a/3.13/alpine3.21/Dockerfile +++ b/3.13/alpine3.21/Dockerfile @@ -9,6 +9,11 @@ FROM alpine:3.21 # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apk add --no-cache \ @@ -67,6 +72,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-option-checking=fatal \ --enable-shared \ @@ -132,6 +138,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.13/alpine3.22/Dockerfile b/3.13/alpine3.22/Dockerfile index 19acd8c79..ab5485028 100644 --- a/3.13/alpine3.22/Dockerfile +++ b/3.13/alpine3.22/Dockerfile @@ -9,6 +9,11 @@ FROM alpine:3.22 # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apk add --no-cache \ @@ -67,6 +72,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-option-checking=fatal \ --enable-shared \ @@ -132,6 +138,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.13/bookworm/Dockerfile b/3.13/bookworm/Dockerfile index 8b970193f..ad073c77a 100644 --- a/3.13/bookworm/Dockerfile +++ b/3.13/bookworm/Dockerfile @@ -9,6 +9,11 @@ FROM buildpack-deps:bookworm # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -41,6 +46,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -105,6 +111,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.13/slim-bookworm/Dockerfile b/3.13/slim-bookworm/Dockerfile index c1ae13ef5..95c97cf08 100644 --- a/3.13/slim-bookworm/Dockerfile +++ b/3.13/slim-bookworm/Dockerfile @@ -9,6 +9,11 @@ FROM debian:bookworm-slim # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -66,6 +71,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -139,6 +145,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.13/slim-trixie/Dockerfile b/3.13/slim-trixie/Dockerfile index 4a1525f2b..11113e9aa 100644 --- a/3.13/slim-trixie/Dockerfile +++ b/3.13/slim-trixie/Dockerfile @@ -9,6 +9,11 @@ FROM debian:trixie-slim # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -66,6 +71,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -139,6 +145,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.13/trixie/Dockerfile b/3.13/trixie/Dockerfile index 943231b87..5189aa9e3 100644 --- a/3.13/trixie/Dockerfile +++ b/3.13/trixie/Dockerfile @@ -9,6 +9,11 @@ FROM buildpack-deps:trixie # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.13t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -41,6 +46,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -105,6 +111,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.13t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/alpine3.21/Dockerfile b/3.14/alpine3.21/Dockerfile index c3788113a..53a7dae1d 100644 --- a/3.14/alpine3.21/Dockerfile +++ b/3.14/alpine3.21/Dockerfile @@ -9,6 +9,11 @@ FROM alpine:3.21 # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apk add --no-cache \ @@ -61,6 +66,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-option-checking=fatal \ --enable-shared \ @@ -126,6 +132,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/alpine3.22/Dockerfile b/3.14/alpine3.22/Dockerfile index 86ea2ccc6..d39e4468e 100644 --- a/3.14/alpine3.22/Dockerfile +++ b/3.14/alpine3.22/Dockerfile @@ -9,6 +9,11 @@ FROM alpine:3.22 # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apk add --no-cache \ @@ -61,6 +66,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-option-checking=fatal \ --enable-shared \ @@ -126,6 +132,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/bookworm/Dockerfile b/3.14/bookworm/Dockerfile index f802ef786..1602a0d04 100644 --- a/3.14/bookworm/Dockerfile +++ b/3.14/bookworm/Dockerfile @@ -9,6 +9,11 @@ FROM buildpack-deps:bookworm # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -40,6 +45,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -118,6 +124,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/slim-bookworm/Dockerfile b/3.14/slim-bookworm/Dockerfile index efc7d3a65..b7fc2244b 100644 --- a/3.14/slim-bookworm/Dockerfile +++ b/3.14/slim-bookworm/Dockerfile @@ -9,6 +9,11 @@ FROM debian:bookworm-slim # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -60,6 +65,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -133,6 +139,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/slim-trixie/Dockerfile b/3.14/slim-trixie/Dockerfile index 1abf7739d..24ad60854 100644 --- a/3.14/slim-trixie/Dockerfile +++ b/3.14/slim-trixie/Dockerfile @@ -9,6 +9,11 @@ FROM debian:trixie-slim # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -60,6 +65,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -133,6 +139,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/3.14/trixie/Dockerfile b/3.14/trixie/Dockerfile index 7aa50e8b8..0eabc8155 100644 --- a/3.14/trixie/Dockerfile +++ b/3.14/trixie/Dockerfile @@ -9,6 +9,11 @@ FROM buildpack-deps:trixie # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python3.14t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # runtime dependencies RUN set -eux; \ apt-get update; \ @@ -40,6 +45,7 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ + --disable-gil \ --enable-loadable-sqlite-extensions \ --enable-optimizations \ --enable-option-checking=fatal \ @@ -118,6 +124,21 @@ RUN set -eux; \ python3 --version; \ pip3 --version +RUN set -eux; \ +# make conventional "python3.14t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \ diff --git a/Dockerfile-linux.template b/Dockerfile-linux.template index d58480c09..ba47b1285 100644 --- a/Dockerfile-linux.template +++ b/Dockerfile-linux.template @@ -13,6 +13,13 @@ if env.variant | contains("bookworm") then "rm -rf /var/lib/apt/lists/*" else "apt-get dist-clean" end + ; + def freethreading: + # https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython + # https://peps.python.org/pep-0703/ + # https://github.com/docker-library/python/pull/1044 + IN(rcVersion; "3.9", "3.10", "3.11", "3.12") + | not -}} {{ if is_alpine then ( -}} FROM alpine:{{ env.variant | ltrimstr("alpine") }} @@ -25,6 +32,13 @@ FROM buildpack-deps:{{ env.variant }} # ensure local python is preferred over distribution python ENV PATH /usr/local/bin:$PATH +{{ if freethreading then ( -}} +# ensure the GIL stays enabled-by-default (even though we supply "--disable-gil" so that the "freethreading" mode is supported by our binaries) +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_GIL +ENV PYTHON_GIL 1 +# (we install a small wrapper script with the conventional "python{{ rcVersion }}t" name to provide so-called "freethreading" behavior in a way that matches the current-as-of-2025 ecosystem conventions: https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + +{{ ) else "" end -}} {{ if rcVersion | IN("3.9", "3.10", "3.11", "3.12") then ( -}} {{ # only set LANG on versions less than 3.13 -}} # cannot remove LANG even though https://bugs.python.org/issue19846 is fixed @@ -197,6 +211,9 @@ RUN set -eux; \ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ ./configure \ --build="$gnuArch" \ +{{ if freethreading then ( -}} + --disable-gil \ +{{ ) else "" end -}} --enable-loadable-sqlite-extensions \ {{ # https://github.com/docker-library/python/pull/980 (fixing PGO runs tests that fail, but shouldn't) @@ -338,6 +355,23 @@ RUN set -eux; \ {{ ) else "" end -}} pip3 --version +{{ if freethreading then ( -}} +RUN set -eux; \ +# make conventional "python{{ rcVersion }}t" style wrappers (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + for exe in /usr/local/bin/python3*; do \ + bin="$(basename "$exe")"; \ +# ignore "python*-config" + [ "${bin%-config}" = "$bin" ] || continue; \ +# ignore existing "python*t" binaries (these are because we compile with --disable-gil) + [ "${bin%t}" = "$bin" ] || continue; \ + printf '#!/usr/bin/env sh\nset -eu\nexport PYTHON_GIL=0\nexec "%s" "$@"\n' "$bin" > "${exe}t"; \ + chmod +x "${exe}t"; \ + "${exe}" -c 'import sys; assert(sys._is_gil_enabled())'; \ + "${exe}t" -c 'import sys; assert(not sys._is_gil_enabled())'; \ + done +# TODO THIS IS NOT A TENABLE LONG-TERM SOLUTION AS OUR BUILDS ARE NO LONGER ABI-COMPATIBLE, DESPITE THE POSSIBILITY THAT THEY MIGHT BE THAT'S SEMI-IMPLIED IN "Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled" (https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython) + +{{ ) else "" end -}} # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends) RUN set -eux; \ for src in idle3 pip3 pydoc3 python3 python3-config; do \