-
Notifications
You must be signed in to change notification settings - Fork 8
Mark extensions as free-threading-compatible and build wheels #233
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
base: develop
Are you sure you want to change the base?
Conversation
There is global state, since there are no heap types. So this won't fly that easily I am affraid. |
Our approach up until now has been that static types are acceptable. Many other packages with static types (namely NumPy, SciPy and others) have shown that, in practice, static types are okay. If you want, I could work on converting all the static types to heap types. However, since that's a bit more of an effort, I'd suggest we merge this and do that as a follow-up. What do you think? |
Okay, that is good to know coming from a core developer. Heap types make things a lot more difficult generally, so I have stuck with static types for this library. It is just something I do on the side. (It is in my work time, but I cannot dedicate huge chunks of time to it). Given that this package is marked as "essential" for the python ecosystem, this change cannot be merged without any tests that assure within reason that it actually works.
Really, does every dependency have to support free-threading for free-threading to work? Why not just use builtin |
I agree with this. I can try to work on adding more testing, if you can give some guidance on what exactly it is that you wanna see more heavily tested. My initial, as it turns out incorrect, assumption was that the tests in
|
I don't know what is sufficient because I haven't read up on free-threading yet. igzip_threaded makes sure each thread gets its own instantiation of an object so they can operate independently. There is explicit GIL dropping code in the methods of such objects. I suppose with a proper free-threading thing the GIL never needs to be dropped, because it is not there and the GIL dropping code is simply empty. In that case, yes the igzip_threaded tests should be sufficient. |
Well, it is sort if inevitable really. This library is used heavily in bioinformatics and those work loads do benefit a lot from threading. So this would needed to be done at some point anyway. |
If you're referring to this piece of code, this can stay as-is under the free-threaded build. Since the GIL is not there under the free-threaded build, this only attaches to/detaches from the CPython runtime. There's some improvements that can be made there, like using the critical section API introduced in 3.13+, but that can also be a follow-up issue. |
If its "good enough" for now then sure. Let's merge it if the tests pass. |
FWIW this isn't quite the right mental model. Maybe read through this to understand how the C API in the GIL-enabled and free-threaded builds are actually identical, and in fact you still need to explicitly attach and detach from the runtime: There are also lots of other suggestions in the guide I linked to for expanding support for free-threading. In particular, I'd try to think about adding explicitly multithreaded tests and perhaps running tests under ASAN or TSAN to be very sure there aren't any issues. |
Ah! So it is indeed as non-trivial as I initially suspected. Thanks for mentioning this. I will investigate and try to add free threading support at some point, but I will not do it at a whim. |
Hopefully not so bad - at least if you were handling the GIL correctly on the GIL-enabled build. The point I was trying to make is that correct multithreaded native Python extensions look mostly the same on the GIL-enabled and free-threaded builds - you need to do exactly the same things to avoid hangs and deadlocks. The main difference is that state can be simultaneously mutated from multiple threads, so new kinds of issues are possible on the free-threaded build. That said, you already have
I think @lysnikolaou opened this because he'd like to work on it. Both of us are on a team at Quansight Labs that are working on ecosystem support for free-threading, and we have funding. Since Of course we'd very much appreciate code review and your participation in discussions. That said, one of our overarching goals in this project is to not be a burden to maintainers and we'll endeavor to treat your time and attention seriously. |
Alright. I am glad that you are willing to invest into this. I need to give this a proper review though and make sure I am up to speed on the free-threading stuff. This should be less work than implementing it myself, but I cnanot give an ETA as I am quite busy at the moment. |
Checklist
Hi there! 👋
I'm opening this PR to implement support for the free-threaded build. I checked that there's no global state and you're locking when compressor/decompressor objects are shared, so we should be good to go. Hopefully this helps. Let me know if I can help any other way!