Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
picnixz left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 meanme 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).
yoney commentedOct 25, 2025
@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! |
Uh oh!
There was an error while loading.Please reload this page.
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
emmatyping commentedOct 26, 2025
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 fromhttps://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
yoney commentedOct 27, 2025
@emmatyping Thanks for pointing to the |
9479a62 intopython:mainUh oh!
There was an error while loading.Please reload this page.
The methods are already wrapped with a lock, which makes them thread-safe infree-threaded build. This replaces `PyThread_acquire_lock` with `PyMutex` andremoves some macros and allocation handling code.Also add a test for free-threading to ensure we aren't getting data races andthat the locking is working.
Uh oh!
There was an error while loading.Please reload this page.
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