From dd4061b6f5b4a18e52d3710636ebae9b15a16471 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 09:24:53 +0200 Subject: [PATCH 1/9] declare free-threading compatible --- zmq/backend/cython/_zmq.py | 1 + 1 file changed, 1 insertion(+) diff --git a/zmq/backend/cython/_zmq.py b/zmq/backend/cython/_zmq.py index fc16087aa..5c7b8e453 100644 --- a/zmq/backend/cython/_zmq.py +++ b/zmq/backend/cython/_zmq.py @@ -1,3 +1,4 @@ +# cython: freethreading_compatible = True """Cython backend for pyzmq""" # Copyright (C) PyZMQ Developers From 3ef57e145c7792423a14b697a767933b931a3fde Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 10:01:09 +0200 Subject: [PATCH 2/9] try setting up free-threading tests --- .github/workflows/test.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64d78a588..bf856adf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: zmq: bundled - os: macos-14 - python: "3.13-dev" + python: "3.13" zmq: bundled - os: macos-13 @@ -86,7 +86,11 @@ jobs: python: "3.12" - os: ubuntu-22.04 - python: "3.13-dev" + python: "3.13" + + - os: ubuntu-22.04 + python: "3.13" + free_threading: free_threading - os: windows-2022 python: "3.7" @@ -97,7 +101,7 @@ jobs: arch: x64 - os: windows-2022 - python: "3.13-dev" + python: "3.13" arch: x64 steps: @@ -105,6 +109,7 @@ jobs: - name: setup python uses: actions/setup-python@v5 + if: ${{ !matrix.free_threading }} with: python-version: ${{ matrix.python }} architecture: ${{ matrix.arch || 'x64' }} @@ -112,6 +117,13 @@ jobs: allow-prereleases: true cache: pip + - name: setup python (free threading) + uses: deadsnakes/action@v3.1.0 + if: ${{ matrix.free_threading }} + with: + python-version: ${{ matrix.python }} + nogil: true + - name: setup coverage if: startsWith(matrix.python, 'pypy') || startsWith(matrix.python, '3.12') run: | From 4d90fa5cb2415f8d8d4f17b59cd4240cdc90cef7 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 11:22:57 +0200 Subject: [PATCH 3/9] install for free threading --- .github/workflows/test.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf856adf5..4eaac1fec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -139,6 +139,11 @@ jobs: run: | pip install --upgrade pip wheel pip install -r test-requirements.txt + + - name: install free-threading dependencies + if: ${{ !matrix.free_threading }} + run: | + pip install --upgrade --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython - name: remove tornado if: matrix.tornado == 'none' @@ -192,12 +197,18 @@ jobs: echo ZMQ_DRAFT_API=1 >> "$GITHUB_ENV" - name: build pyzmq + if: ${{ !matrix.free_threading }} run: | pip install -v -e . + - name: build pyzmq (free threading) + if: ${{ matrix.free_threading }} + run: | + pip install -v --no-build-isolation . + - name: import zmq run: | - python -c "import zmq" + python -I -c "import zmq" - name: run tests run: | From cd38b2a9952edfbb179d02d26bee8f580a4ca373 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 12:20:38 +0200 Subject: [PATCH 4/9] get build deps for free-threading --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4eaac1fec..2ff5e6721 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -141,9 +141,12 @@ jobs: pip install -r test-requirements.txt - name: install free-threading dependencies - if: ${{ !matrix.free_threading }} + if: ${{ matrix.free_threading }} run: | - pip install --upgrade --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython + # need build deps for no-build-isolation + # remove after Cython 3.1 + pip install scikit-build-core ninja packaging + pip install --upgrade --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython - name: remove tornado if: matrix.tornado == 'none' From dff5fb3f401736dd29e8cea6b18adead3157fd8b Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 13:35:09 +0200 Subject: [PATCH 5/9] use miniconda to setup cp313 deadsnakes is pretty out of date --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ff5e6721..2536845fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -118,11 +118,12 @@ jobs: cache: pip - name: setup python (free threading) - uses: deadsnakes/action@v3.1.0 - if: ${{ matrix.free_threading }} + uses: conda-incubator/setup-miniconda@v3 with: - python-version: ${{ matrix.python }} - nogil: true + python-version: ${{ matrix.python-version }} + channels: defaults,ad-testing/label/py313_nogil + activate-envirionment: nogil + show-channel-urls: true - name: setup coverage if: startsWith(matrix.python, 'pypy') || startsWith(matrix.python, '3.12') From f3e0421f648418667c499e619144d5a2890a8041 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 14:04:42 +0200 Subject: [PATCH 6/9] need pip --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2536845fc..3e7d22ea7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -124,6 +124,9 @@ jobs: channels: defaults,ad-testing/label/py313_nogil activate-envirionment: nogil show-channel-urls: true + packages: + - python=${{ matrix.python-version }} + - pip - name: setup coverage if: startsWith(matrix.python, 'pypy') || startsWith(matrix.python, '3.12') From 50560d4308eecc898daf56b56a5348e817b5dd3b Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 14:26:06 +0200 Subject: [PATCH 7/9] try setup-micromamba --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e7d22ea7..a45be15f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -118,15 +118,30 @@ jobs: cache: pip - name: setup python (free threading) - uses: conda-incubator/setup-miniconda@v3 + if: ${{ matrix.free_threading }} + uses: mamba-org/setup-micromamba@v1 with: - python-version: ${{ matrix.python-version }} - channels: defaults,ad-testing/label/py313_nogil - activate-envirionment: nogil - show-channel-urls: true - packages: - - python=${{ matrix.python-version }} - - pip + environment-name: nogil + condarc: | + channels: + - ad-testing/label/py313_nogil + - defaults + create-args: >- + python=${{ matrix.python-version }} + pip + + - name: activate python (free threading) + if: ${{ matrix.free_threading }} + # light activate, just add env to path + # run this in micromamba-shell + # so we don't have to for the rest + run: | + echo $PATH + echo "PATH=$PATH" >> "$GITHUB_ENV" + echo "PYTHON_NOGIL=1" >> "$GITHUB_ENV" + shell: micromamba-shell {0} + + - name: setup coverage if: startsWith(matrix.python, 'pypy') || startsWith(matrix.python, '3.12') @@ -147,6 +162,9 @@ jobs: - name: install free-threading dependencies if: ${{ matrix.free_threading }} run: | + conda info + which -a python + which -a pip # need build deps for no-build-isolation # remove after Cython 3.1 pip install scikit-build-core ninja packaging From 678da52f26b3153dca98660e0828f2e819c74a74 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 14:36:43 +0200 Subject: [PATCH 8/9] ignore weird typecheck on free-threaded --- examples/cython/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cython/setup.py b/examples/cython/setup.py index ef37fcbfd..b25d2d497 100644 --- a/examples/cython/setup.py +++ b/examples/cython/setup.py @@ -12,4 +12,4 @@ include_dirs=zmq.get_includes() + [numpy.get_include()], ) ] -setup(name="cython-zmq-example", ext_modules=cythonize(extensions)) +setup(name="cython-zmq-example", ext_modules=cythonize(extensions)) # type: ignore From 8e78ea9c27fa636e88b1c956b976ee0e30c2bd3a Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 2 Aug 2024 14:39:44 +0200 Subject: [PATCH 9/9] disable GIL via env --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a45be15f4..74706922d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -138,7 +138,7 @@ jobs: run: | echo $PATH echo "PATH=$PATH" >> "$GITHUB_ENV" - echo "PYTHON_NOGIL=1" >> "$GITHUB_ENV" + echo "PYTHON_GIL=0" >> "$GITHUB_ENV" shell: micromamba-shell {0}