-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-116738: Use PyMutex for bz2 module #140555
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
Conversation
This reverts commit 5362112.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and sorry for the back-and-forth. A small tip: when I (and I mean me explicitly) suggest something (and don't explicitly request changes), you don't need to directly follow my advice if my suggestion was phrased as a question (that question could be addressed to a wider audience).
|
@picnixz Thanks for the review! I’m glad we discovered Since the changes were quite small, I just created the extra commit, knowing we might need to revert if needed. This is just part of a good review process! |
emmatyping
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this looks good
|
Oh, perhaps we should add a test on free-threading to ensure we aren't getting data races and the locking is working? Feel free to take some inspiration from https://github.com/python/cpython/blob/main/Lib/test/test_zstd.py#L2668 |
vstinner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@emmatyping Thanks for pointing to the |
I was initially looking into the
bz2module for free-threading. The methods are already wrapped with a lock, which I believe is primarily used to release the GIL. This locking makes the methods thread-safe in free-threaded build. I replacedPyThread_acquire_lockwithPyMutex, which releases the GIL when the thread is parked. This change removes some macros and allocation handling code.cc: @mpage @colesbury