-
Notifications
You must be signed in to change notification settings - Fork 43
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
Can free-threading wheel builds be made available on PyPI? #119
Comments
As far as I can tell, CFFI will crash Python or corrupt memory if you force it to run in a free-threaded Python. That's why we don't provide free-threaded CFFIs. |
There are numerous issues to solve before CFFI has any real hope of "just working" under the In any case, we've been playing with it, and will continue to do so, but we absolutely will not be publishing CFFI wheels for the IMO unstable t-ABI wheels are just an attractive nuisance, providing a false sense of security to folks playing around that their code might actually be safe, and leading to a lot of bug report noise at this stage, since the typical failure mode is almost always either a hang or a segfault. I'm going to pin this issue to (hopefully) head off duplicates. PS, since I couldn't resist playing with it again: as of 3.13rc1 with a default-GIL-disabled Python build against the current |
(also see #126 for overall status on that stuff) |
This is understandable, but it seems CFFI can still be installed in a Python free-threaded build. It will just compile CFFI from source. Worse, under Windows the produced package will crash when importing: |
@pitrou If that's correct, then (1) why?? and (2) if someone can provide the necessary code to add to the CFFI sources to prevent that from happening, it would be nice. |
Maybe this?
|
Yeah, I think that would be sufficient. Though, in the Windows case, it might be that So perhaps adding a runtime check using |
I think that CPython is meant to switch to a GIL-having mode when it tries to import an extension module that doesn't explicitly say "I support free-threading". If that's the case, then it should still work and not crash. If it doesn't, then it's a bug in either CPython or CFFI (it is probably in the interaction between the two, i.e. CFFI doing something that somehow makes the free-threading CPython unhappy). In that case, maybe CFFI should add a warning and not an error. For all I know it actually works in other contexts (e.g. not Windows). |
Yes, but the extension module still needs to be compiled with the More precisely, a Windows Python 3.13 install contains both a |
How did I forget to include setuptools in my list of things to blame? I have no idea. So you are saying that the C API is different, in such a way that if you try to load in |
😆
The ABI is different, yes. That's why the ABI tag is different too (
Well, I don't know much about the free-threading internals, but IIRC they had to change the refcounting implementation to minimize performance regressions. Given that |
CPython could easily have come up with some hack that makes the module not load; for example, a I'd still (seriously) accept a CFFI PR that is a workaround for a setuptools bug exposing a CPython design mistake. That seems like a nonsensical enough proposition to be interesting, if only to remind me why I mostly left the Python ecosystem behind me. |
That's a good point. I suppose that ship has sailed... (and once setuptools is fixed, things will be better hopefully!) |
I know from other issues/PRs (e.g., #40) that making cffi actually thread-safe is a big task. However, a small but easier step is to produce free-threaded wheels. As mentioned in https://docs.python.org/3.13/howto/free-threading-extensions.html#module-initialization
Thus, providing FT wheels doesn't necessarily mean the extension supports it, it simply allows the package to be installed in a FT installation.
I do understand that providing such wheels could make some users believe that cffi is fully multi-threaded. As long as expectations are made clear that hopefully shouldn't be an issue, but that's very easy to say.
In my case I'm trying to provide FT builds of my library (with hopefully actual thread-safe code), and cffi is an optional dependency (rarely used though from what I know). I'm not running multi-threaded code in my tests (yet), and even if I did python would should re-enable the GIL when importing cffi.
The text was updated successfully, but these errors were encountered: