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

[Free-Threaded] Allow Free-Threaded Python Build Fail Gracefully #4321

Closed
FlickerSoul opened this issue Jul 8, 2024 · 2 comments
Closed

Comments

@FlickerSoul
Copy link
Contributor

FlickerSoul commented Jul 8, 2024

As discussed in here, it would be nice to allow PyO3 to fail when building against GIL-less Python. I'm planning to implement this feature so I opened this issue to track discussion regarding this issue.

I was advised to look at the pyo3-build-config crate and the following is my plan of implementation of this feature:

  • Add an additional boolean field (possibly named free_threaded) in InterpreterConfig to indicate whether the interpreter is free-threaded or not.
  • In the build.rs located at pyo3-ffi crate or the one in top-level workspace, add an additional check in configure_pyo3 to validate the interpreter is not free-threaded (from the obtained InterpreterConfig instance), and panic otherwise.
  • Add an additional environment variable (possibly named PYO3_ALLOW_FREE_THREADED) to override the second bullet, to facilitate building during development.

Any advice would be much appreciated! Thanks! :)

Related to: #4265

@FlickerSoul FlickerSoul changed the title [Python 3.13] Allow Free-Threaded Python Build Fail Gracefully [Free-Threaded] Allow Free-Threaded Python Build Fail Gracefully Jul 8, 2024
@davidhewitt
Copy link
Member

This sounds great, yes please!

  • Add an additional boolean field (possibly named free_threaded) in InterpreterConfig to indicate whether the interpreter is free-threaded or not.

Depending on the CPython configuration, it might be that an additional field isn't needed and this can go into build_flags.

  • In the build.rs located at pyo3-ffi crate or the one in top-level workspace, add an additional check in configure_pyo3 to validate the interpreter is not free-threaded (from the obtained InterpreterConfig instance), and panic otherwise.

Yes (though configure_pyo3 returns a result rather than panicking).

  • Add an additional environment variable (possibly named PYO3_ALLOW_FREE_THREADED) to override the second bullet, to facilitate building during development.

Yes please, I think maybe UNSAFE_PYO3_BUILD_FREE_THREADED perhaps? We expect builds to be broken until the moment we've finalised support, so I think hinting at this in the env var might be a good idea.

@davidhewitt
Copy link
Member

Fixed in #4327, thanks @FlickerSoul

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

No branches or pull requests

2 participants