Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for 3.13t #28

Open
wants to merge 11 commits into
base: default
Choose a base branch
from
Open

Conversation

0xDEADFED5
Copy link

add python 3.13t compatibility to twisted-iocpsupport

noticed it was needed after i posted this:
twisted/twisted#12425

@0xDEADFED5
Copy link
Author

0xDEADFED5 commented Feb 7, 2025

GRAALVM_PYTHON is a bit of a hack because the tangle of #ifs in there are pretty good at undefining things needed to build successfully

setup.py Outdated
from Cython.Build import cythonize


macros = None
if sysconfig.get_config_var("abi_thread") == "t":
Copy link
Member

@adiroiban adiroiban Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment explaining why we need these changes

From what I can read at https://docs.python.org/3/howto/free-threading-extensions.html#building-extensions-for-the-free-threaded-build

as long as we use ciwheelbuilder this is not needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will help to have a link to https://docs.python.org/3/howto/free-threading-python.html

and, is this the right way to check for thread free ?

In the Python docs I see

The sysconfig.get_config_var("Py_GIL_DISABLED") configuration variable can be used to determine whether the build supports free threading. If the variable is set to 1, then the build supports free threading. This is the recommended mechanism for decisions related to the build configuration.

@adiroiban
Copy link
Member

Thanks for the PR... I pushed some changes to enable 3.13 wheels generation on this PR.

I need to read more about the thread free variant of 3.13 ...

We use cibuildwheel and it looks like we need to use CIBW_ENABLE

https://cibuildwheel.pypa.io/en/stable/options/#enable

@0xDEADFED5
Copy link
Author

0xDEADFED5 commented Feb 7, 2025

probably more extensive testing needs to be done on the 3.13t binary, but it does work for my use case.

3.13t is going to be an extremely limited pool of users since you have to build Python yourself to even use 3.13t right now. oh wait, i was thinking of JIT. i forgot the installer has a free-threaded option.

@adiroiban adiroiban closed this Feb 10, 2025
@adiroiban adiroiban reopened this Feb 10, 2025

macros = None
if sysconfig.get_config_var("abi_thread") == "t":
macros = [("GRAALVM_PYTHON", "1"), ("Py_GIL_DISABLED", "1")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we don't need this.

Instead, we can just use cibuildwheel and will take care of setting up the build environment.

@adiroiban
Copy link
Member

Somehow cibuildwheel is not configured ok ... it is still producing wheels for 3.6 and 3.7 ... and there are no wheels for Python 3.13 t

20 wheels produced in 13 minutes:
  twisted_iocpsupport-1.0.4-cp310-cp310-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp310-cp310-win_amd64.whl          46 kB
  twisted_iocpsupport-1.0.4-cp311-cp311-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp311-cp311-win_amd64.whl          47 kB
  twisted_iocpsupport-1.0.4-cp312-cp312-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp312-cp312-win_amd64.whl          47 kB
  twisted_iocpsupport-1.0.4-cp313-cp313-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp313-cp313-win_amd64.whl          46 kB
  twisted_iocpsupport-1.0.4-cp36-cp36m-win32.whl               46 kB
  twisted_iocpsupport-1.0.4-cp36-cp36m-win_amd64.whl           54 kB
  twisted_iocpsupport-1.0.4-cp37-cp37m-win32.whl               43 kB
  twisted_iocpsupport-1.0.4-cp37-cp37m-win_amd64.whl           48 kB
  twisted_iocpsupport-1.0.4-cp38-cp38-win32.whl                43 kB
  twisted_iocpsupport-1.0.4-cp38-cp38-win_amd64.whl            47 kB
  twisted_iocpsupport-1.0.4-cp39-cp39-win32.whl                43 kB
  twisted_iocpsupport-1.0.4-cp39-cp39-win_amd64.whl            47 kB
  twisted_iocpsupport-1.0.4-pp310-pypy310_pp73-win_amd64.whl   45 kB
  twisted_iocpsupport-1.0.4-pp37-pypy37_pp73-win_amd64.whl     44 kB
  twisted_iocpsupport-1.0.4-pp38-pypy38_pp73-win_amd64.whl     44 kB
  twisted_iocpsupport-1.0.4-pp39-pypy39_pp73-win_amd64.whl     45 kB

@adiroiban
Copy link
Member

I think that the build is now ok

  twisted_iocpsupport-1.0.4-cp310-cp310-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp310-cp310-win_amd64.whl          46 kB
  twisted_iocpsupport-1.0.4-cp311-cp311-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp311-cp311-win_amd64.whl          47 kB
  twisted_iocpsupport-1.0.4-cp312-cp312-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp312-cp312-win_amd64.whl          47 kB
  twisted_iocpsupport-1.0.4-cp313-cp313-win32.whl              42 kB
  twisted_iocpsupport-1.0.4-cp313-cp313-win_amd64.whl          46 kB
  twisted_iocpsupport-1.0.4-cp313-cp313t-win32.whl             44 kB
  twisted_iocpsupport-1.0.4-cp313-cp313t-win_amd64.whl         49 kB
  twisted_iocpsupport-1.0.4-cp38-cp38-win32.whl                43 kB
  twisted_iocpsupport-1.0.4-cp38-cp38-win_amd64.whl            47 kB
  twisted_iocpsupport-1.0.4-cp39-cp39-win32.whl                43 kB
  twisted_iocpsupport-1.0.4-cp39-cp39-win_amd64.whl            47 kB
  twisted_iocpsupport-1.0.4-pp310-pypy310_pp73-win_amd64.whl   45 kB
  twisted_iocpsupport-1.0.4-pp37-pypy37_pp73-win_amd64.whl     44 kB
  twisted_iocpsupport-1.0.4-pp38-pypy38_pp73-win_amd64.whl     44 kB
  twisted_iocpsupport-1.0.4-pp39-pypy39_pp73-win_amd64.whl     45 kB

Can you please try the wheel version from https://github.com/twisted/twisted-iocpsupport/actions/runs/13239410326/artifacts/2563932853

this should be the version that we will be publish to PyPi

Thanks

@0xDEADFED5
Copy link
Author

just tested twisted_iocpsupport-1.0.4-cp313-cp313t-win_amd64.whl from your artifacts and confirmed it's working with twisted 23.10 and twisted 24.11

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes.

I left a few inline comments.

I am not an expert in Python C extensions... so I just want to make sure that we are ok and future developers will know why we made the current changes.

Can you please check if the changes in setup.py are needed ?

Maybe they are needed to build outside of of cibuildwheel ... but from the docs, it looks like only Py_GIL_DISABLED is needed.

I think that GRAALVM_PYTHON is not related to GIL... and I don't know if it has any effect with our current build process.

Please add some notes about why we need GRAALVM_PYTHON for free threading.

Thanks

setup.py Outdated
from Cython.Build import cythonize


macros = None
if sysconfig.get_config_var("abi_thread") == "t":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will help to have a link to https://docs.python.org/3/howto/free-threading-python.html

and, is this the right way to check for thread free ?

In the Python docs I see

The sysconfig.get_config_var("Py_GIL_DISABLED") configuration variable can be used to determine whether the build supports free threading. If the variable is set to 1, then the build supports free threading. This is the recommended mechanism for decisions related to the build configuration.

@0xDEADFED5
Copy link
Author

0xDEADFED5 commented Feb 15, 2025

sorry, i just noticed your comments. yes, i added that code for building locally. i'll add some notes explaining my reasoning tomorrow. basically, it's not easy to set the correct defines because in the iocpsupport.c that gets generated the options get #undef and #define again in many places. GRAALVM_PYTHON just happened to set the right options needed to compile.

edit- and sysconfig.get_config_var("Py_GIL_DISABLED") sounds good!

@adiroiban
Copy link
Member

GRAALVM_PYTHON just happened to set the right options needed to compile.

Thanks for the info.
I think that it's important to have this comment inside the source file.

As long as the code is documented, I think that we are good to merge this and trigger a new release for twisted-iocpsupport

Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants