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

Make ffi_init_once thread-safe in free threaded build #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

colesbury
Copy link

@colesbury colesbury commented Nov 13, 2024

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

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.
@colesbury
Copy link
Author

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:

  • I added a "polyfill" for PyDict_GetItemRef, but that sort of thing is nicely provided. by https://github.com/python/pythoncapi-compat/. Would you be interested in using that?
  • It's probably cleaner and simpler to make init_once_cache have the same lifetime as its FFIObject instead of lazily initializing it. I went with the smaller code change for now, but let me know what you think.

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.

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

Successfully merging this pull request may close these issues.

1 participant