-
Notifications
You must be signed in to change notification settings - Fork 47
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
Make ffi_init_once thread-safe in free threaded build #143
base: main
Are you sure you want to change the base?
Conversation
Lock the FFI object when initializing the init_once_cache dictionary and use PyDict_GetItemRef in places where the dictionary's value may be concurrently modified.
Hi @nitzmahone - I'm still working through the CFFI free-threading issues, but I figured it'd be helpful to get some feedback on a small change. On that note:
To find thread-safety issues, in addition to reading through the code, I'm using https://github.com/Quansight-Labs/pytest-run-parallel, which I've found to be very effective. |
Hey @nitzmahone - gentle ping. I'd really like to see python-cffi work in the free threading build as a lot of libraries depend on it. I'm happy to do most of the implementation work. |
Hi! Just in case you want an alternative approach, you can make a fork of cffi and implement and test free-threading in it. Ideally you'd advertise it for pip usage too (I think it can be done with a direct github url if you don't want to make a new cffi-xyz package name). Once such a thing exists, is complete, and is reasonably well-tested (either as tests or, better in this case, tested by being in use in various other projects), I'd be up to reviewing a single big pull request. What I won't do is review many small incremental patches---but I'm not speaking for nitzmahone here, only for me. |
Hi Armin - thanks for your suggestion and I appreciate your offer to review a single, big, well-tested PR. A forked, free threading pacakge is a bit awkward because pip doesn't support "free threading" as a constraint: a project can't easily depend on a forked version only for the free threading build. I think there are workarounds, but they require more substantial changes to the build process of packages that depend on cffi. |
I think for now it would be fine if you get enough people to test various projects after changing the line in requirement.txt to point to the github clone. Note also that you shouldn't expect many changes coming from the official cffi repo (there are very few updates nowadays), so keeping up-to-date should be easy. |
Lock the FFI object when initializing the init_once_cache dictionary and use PyDict_GetItemRef in places where the dictionary's value may be concurrently modified.
See #126