-
Notifications
You must be signed in to change notification settings - Fork 248
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
Prevent greenlet from building on free-threaded Python #423
Comments
So, I configured the launch.json file in VSCode and set the "gevent" field to false. After that, I was able to use Python's free-threaded version, which disables the GIL (Global Interpreter Lock) without any issues. |
If you load the extension, it's going to initialize the GIL. If you force Python to not initialize the GIL, the extension will be broken. Do not do this. |
You can check if Thinking further afield - is there an issue for supporting the free-threaded build? I'm actively working on adding support for free-threaded Python in community packages and can offer help and advice. There's also https://py-free-threading.github.io which has some advice for porting extensions. |
So I just need: // greenlet.h
#ifdef Py_GIL_DISABLED
#error Nope right out of that.
#endif
Unfortunately yes. greenlet itself implicitly depends on the GIL to keep its internal structures consistent. We could add a bunch of locks internally to take care of that, but that leaves bigger issues. I'm not saying they can't be dealt with, but they are certainly factors that make trying to support GILless CPython risky. Bigger issue #1 is that greenlet copies and mutates internal CPython state and then restores it, and that data must be completely consistent. That state should all belong to one thread, and shouldn't be manipulated by other threads, but that's a lot of wishful thinking that I don't know is actually true, especially when it comes to internal CPython data structures that can be manipulated as side-effects (e.g., there has to be a list of threads and thread creating and destruction has to manipulate that list; if something we copy/restore during greenlet switching refers to that list, concurrent manipulation of it could be deadly). Extensive testing would be required (and its hard to test for race conditions.) Bigger issue #2 is effectively the same issue that the Python community as a whole has to deal with --- race conditions that have been hidden until now --- only writ large. Because greenlets are fully cooperative, users are used to ignoring race conditions altogether. Already when you try to mix threads with greenlets things get dicy --- gevent has a lot of code to try to make this safe and workable, but it's not perfect --- and actually adding true concurrency on top of that is only going to magnify the problem. (Oh, and also, gevent depends on the GIL for some of its invariants as well, so gevent would have to be reworked too.) Again, not an insurmountable problem (and technically not one that greenlet can really do anything about), but a factor to consider before deciding if it's worth spending the effort. |
You need to Thanks for the context! I'm not sure whether pip will continue to install the cp313t wheels on pypi if there is a newer version without cp313t wheels. |
We don't set the flag that indicates we're compatible with free-threading, so loading us would automatically enable the GIL according to the Python documentation. It is thus misleading that we can even build on a free-threaded Python and get the "t" suffix, e.g., "313t".
The
make-manylinux
script has some support for skipping free-threaded Python's, but it's neither complete nor sufficient.The trouble is that CPython doesn't document a way to detect at compile time that it is built on free-threading. At least, not that I could see in the "Porting to 3.13" and "C API Changes" sections of the release notes.
The text was updated successfully, but these errors were encountered: